You want to create your own Button and use it in project written in Flex Builder. You designed the Button in Flash Professional, created a pretty skin, and added label with your favorite font. But how can you easily use this button and communicate with it using the clear and strict Button class, instead of the dynamic MovieClip class?
Design your button in Flash Professional. Create class Button in your project. Set linkage to your button to Button class. Then you must embed SWF file using [Embed] metatag with param mimeType="application/octet-stream". Then, load embedded asset using Loader.loadBytes() method. Then just wait 1 frame – and you can use all possibilities of your Button.
public var labelTxt:TextField;
public function get label():String
{
return labelTxt.text;
}
public function set label(value:String):void
{
labelTxt.text = value;
}
[Embed("../assets/assets.swf",
mimeType="application/octet-stream")]
private var AssetsAsset:Class;
private var myLoader:Loader = new Loader(); ... // this can be written in constructor var ldrContext:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain); myLoader.loadBytes( new AssetsAsset (), ldrContext );
private var sprite:Sprite = new Sprite();
...
// this can be written in constructor
sprite.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
...
private function enterFrameHandler(event:Event):void
{
var button:Button = new Button();
addChild(button);
button.label = "I'm a button from flash!";
sprite.removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
Just try it! After performing these actions right you will see your pretty button on the stage with label that we set :)