Tuesday, February 24, 2009

Using a Flash Component in Flex

There's not a lot of documentation on creating components for Flex in Flash, but it's fairly simple to do.

Prerequisites: CS3, Flex Component Kit for CS3 installed
Basic Steps: Create Flash movieclip (put the movieclip on frame 1 of your main timeline) then click on Commands/Convert Symbol to Flex Component and publish.
Flash will publish a swc file.
Your new Flex component will have the name of your movieclip and will be part of the mx.flash.IUMovieClip base class

In Flex, copy the swc into your libs folder
Then you can reference your new component from within Flex by it's class name (name of MovieClip)
note: new component must have x and y set and be in an absolute container.

With that, you can now control the timeline - play(); stop(); gotoAndPlay();
var myFlashComp:myFlashComp = new myFlashComp();
myFlashComp.x = 0;
myFlashComp.y = 0;
addChild(myFlashComp);
myFlashComp.gotoAndPlay(50);

If you want to reference other things in your movieclip, like maybe a dynamic text field, you need to create an actionscript class by the same name as the movieclip and import the flash.text.TextField

No comments: