Loading flash library asset in Flex

The below is the code to load flash library asset (using linkage name) on Flex.

<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml&#8221; creationComplete=”onCreationComplete()” >
import mx.core.UIComponent;
private function onCreationComplete():void{
var swfLoader:Loader = new Loader();
swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onSWFLoadComplete);
swfLoader.load(new URLRequest(“flash.swf”));
private function onSWFLoadComplete(event:Event):void{
var tempClass:Class = event.target.applicationDomain.getDefinition(“libraryAsset”) as Class;
var movieClip:MovieClip = new tempClass() as MovieClip;
var uiComp:UIComponent = new UIComponent();

    • etokcan
    • August 13th, 2009

    great example, thank you. i would like to ask a few questions though.

    1- could you provide (that is if you still have it) the source code or the fla for the flash.swf?

    2- why did you prefer to put the movieclip in a UIComponent rather than directly adding it to the scene?

    3-when i import a picture to the library in flash, give it a linkage name and compile, size of the swf file is way smaller than that of the picture. however when i use actionscript’s compile time embed methods in flex builder, the result i obtain is always slightly bigger than the picture. how does flash compress the image and how can i apply it to my own code?

    • Thanks,
      1. i don’t have the source code (as they were very old).
      2. I preferred UIComponent, than stage to develop custom components in future easily.
      3. Either flash and flex the compression ratio for images are all the same,
      for flex difference lies in the swc files imported in default (you can prefer removing them in case you don’t need)

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: