开发者

How to add flex controls to my AS3 project?

I'm absolute newbie in Flash development but anyway I need to do something. I have a pure AS3 project that plays video from youtube (chromeless player). I need to add some controls to manage this player. I don't know how to do that? If I just add mxml file into the project nothing h开发者_开发百科appens. How to bind this file to as3? Thanks


Flex components need to have UIComponent parent to function properly. If your player is based on Sprite, controls will not be initialized.

There is a trick to use Flex controls in the Sprite, but only after initialization in Flex Application. If you don't have Application, no luck.


You could use an AS3-only alternative. One library I've used is minimalcomps which offers some simple but effective controls for use in any AS3 project.


You can't use MXML, but nobody stops you to create your own controls if they are simple.


A short and simple example of how to add a button with an image:

loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
loader.load(new URLRequest('http://i1.nyt.com/images/misc/nytlogo379x64.gif'));


function onComplete(event:Event):void
{
    var button:Sprite = new Sprite();
    button.addChild(event.currentTarget.content);
    addChild(button);
    button.buttonMode = true;
    button.addEventListener(MouseEvent.CLICK, onButtonClick);
}

function onButtonClick(event:MouseEvent):void
{
    trace ('click');
}

This would be the most basic version of a button with a loaded bitmap image. Normally you would like to check for errors as well... what to do if the image is not found, or when you're not allowed to access it.

If you're going to need more then one button you could make a class which accepts an url, so you could just pass the url to the class and the button would be created.

A completely other way to approach this is with an SWC file, you could create the buttons in the Flash IDE and export them as an swc, which you can embed and use in your pure AS3 project.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜