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();
addChild(x);

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();
addChild(wrapper);
wrapper.addChild(x);

That’s all there is to it.

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

Adobe Media Encoder CS4, F4V, and navigation cue points

I just wasted a few hours trying to get my Actionscript to catch navigation cue points that were supposed to be embedded in a F4V video. The original video was converted in Media Encoder CS4 from an AVI. What’s strange is that when I import the F4V into Flash and attach it to the FLVPlayback component, the component inspector clearly lists the cue points. But nothing is fired when the video plays. This post identified the bug. I’m still not sure if it’s a problem with the encoding process in Encoder or if it’s with the F4V wrapper format. I guess it’s back to using the FLV format.