views:

863

answers:

2

Hi, I am new to Flash/Flex. I would like to use a Component I created in Flash extending fl.core.UIComponent. How do I use this in Flex? Do I just export it as a swc or do I have to use the Flash Flex 3 kit which will convert it to a UIMovieClip. That does not sound right.

I would appreciate a few simple steps describing the process. Thanks Sanoran

A: 

Just import the .as file into your flex app. Use rawChildren.addChild instead of plain addChild to add it to the display list because flex overrides the default addChild method to accept only mx.core.UIComponent and its derived classes.

Update: You can't use FLA in flex, so if your component is not just an AS class extending fl.core.UIComponent, you should either export it to SWC or load the corresponding SWF at runtime to the flex app.

Amarghosh
Note though, if you do it this way, you can't use the Flash IDE to author the visual components. IE, no .fla files.
secoif
You can't use fla in flex anyway, can you?
Amarghosh
I thought OP was asking about using AS class extending core uicomponent. If it includes FLAs, you should either export as SWC or load SWF in runtime.
Amarghosh
Thank you. sanoran.
Sanoran
+1  A: 

You can publish your file as a .swf and use the SWFLoader to load it, just remember the paths are relative to your run/debug directories.

My understanding is swc files are generally library files, rather than visual components, because you want the libraries included at compile time (swc) rather than at runtime (swf).

  var loader = new SWFLoader();

   // set autoload to false just so we KNOW when it loads. Also prevents
   // us from accidently loading it twice by calling load() later
   loader.autoLoad = false;
   loader.addEventListener(Event.INIT, function (nt:Event) {
       // Remove event listener so can be garbage collected
    event.currentTarget.removeEventListener(event.type, arguments.callee);  
       // note we can the loader, rather than
       // loader.content
       someIVisualElementContainer.addElement(loader);

   });

   // relative to bin-debug or bin-release
   loader.source = "movie.swf";

  loader.load();
secoif
My example assumes Flex4 even though you said Flex3, simply change addElement to addChild for a Flex3 mx component.
secoif
Thank you. sanoran.
Sanoran