Using a movieclip you created in Flash, in Flex

If you want to create a nifty movieclip in Flash but want to use it in your Flex application, you will need to export it as a .swc then import it into Flex. The first step is to right click on the movieclip in your Flash library and select Component Definition. The main thing to enter in the pop up window is the Class name. This will be the name of the class you instantiate in Flex. After you click OK and the window closes, right click on the movieclip in the library again and select Export SWC file. Once that’s done, you’ll need to add the .swc to your Flex library. In Flex, under the Project menu, select Properties. Go to the Flex Build Path section. Click on the Library Path tab. Click the Add SWC button and navigate to the file you just created.

That would seem to be all but it’s not. If you try create an instance of the class as you would any other class in Flex, you’d get an error. For example:

var x:myClass = new myClass();

will give you this error: Type Coercion failed: cannot convert myClass@6f3c9c1 to mx.core.IUIComponent.

The trick is to wrap your class with a UIComponent. So your code should look like this:

var x:myClass = new myClass();
var wrapper:UIComponent = new UIComponent();

That’s all there is to it.

Here’s an example of using the FLVPlayback component in Flex