简体   繁体   中英

how to use UIComponent/Flash in Flex

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM