Flexcomps’s Weblog

Loading library assets from flash9 swf to Flex

Posted by: Yogesh Puri on: July 7, 2008

This is a prototype to load external flash9 swf file into flex and using the library items from the swf. In given example we have two library symbols with linkage ids (”mc1″, “mc2″).

Just make sure when you create a movieclip from these definitions, you firstly add these to a UIComponent and then that component to stage or any container, otherwise there will be a conversion error you will be getting

You can download sources from here

Following is the code for the same.

<?xml version=”1.0″ encoding=”utf-8″?>

<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” creationComplete=”init()” layout=”absolute”>

<mx:Script>

<![CDATA[

import mx.core.UIComponent;

//-------- Declare Variables --------

private var swfLoader:Loader;

private var fileURL:URLRequest;

//----- Initialize Function ------------

private function init():void{

//    Security.allowDomain("*");

swfLoader = new Loader();

_fileURL = new URLRequest("sample.swf");

configureListeners(swfLoader.contentLoaderInfo);

try{

swfLoader.load(_fileURL);

}

catch(e:IOErrorEvent){

trace(e.toString());

}

}

private function configureListeners(dispatcher:IEventDispatcher):void {

dispatcher.addEventListener(Event.COMPLETE, onSWFLoaded);

dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);

dispatcher.addEventListener(Event.INIT, initHandler);

dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);

dispatcher.addEventListener(Event.OPEN, openHandler);

dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);

dispatcher.addEventListener(Event.UNLOAD, unLoadHandler);

}

private function completeHandler(event:Event):void {

trace("completeHandler: " + event);

}

private function httpStatusHandler(event:HTTPStatusEvent):void {

trace("httpStatusHandler: " + event);

}

private function initHandler(event:Event):void {

trace("initHandler: " + event);

}

private function ioErrorHandler(event:IOErrorEvent):void {

trace("ioErrorHandler: " + event);

}

private function openHandler(event:Event):void {

trace("openHandler: " + event);

}

private function progressHandler(event:ProgressEvent):void {

trace("progressHandler: bytesLoaded=" + event.bytesLoaded + " bytesTotal=" + event.bytesTotal);

}

private function unLoadHandler(event:Event):void {

trace("unLoadHandler: " + event);

}

//-----

private function onSWFLoaded(event:Event):void{

var mClip:Class = event.target.applicationDomain.getDefinition("mc1") as Class;

var mClip1:Class = event.target.applicationDomain.getDefinition("mc2") as Class;

var mClipInstance:MovieClip = new mClip() as MovieClip;

var mClipInstance1:MovieClip = new mClip1() as MovieClip;

//trace(mClipInstance.totalFrames);

var uiComp:UIComponent = new UIComponent();

uiComp.addChild(mClipInstance);

uiComp.addChild(mClipInstance1);

addChild(uiComp);

uiComp.x = 100;

uiComp.y = 100;

uiComp.getChildAt(0).x = 150;

}

]]>

</mx:Script>

</mx:Application>


7 Responses to "Loading library assets from flash9 swf to Flex"

Ulti Yogi Sir

Thanks for sharing

Hoping to keep sharing

Thanks
P

i was looking for such a snipped for a very ling time.

unfortunatly i get a compiler error abou mx.flash:UIMovieClip which isn’t available on my system…

any idea?

Hi Nie

Please post your code as it is very difficult to find the issue with a limited information.

[...] Loading Flash 9 Library Assets Into Flex (Thanks To: Yogesh Puri at Flexcomps) [...]

hi, if I dont know linkage names, how can I load all library assets into an array and execute each item as the way you do with “mc1″ and “mc2″?

Can I make this resource Embed and provide some parameters to FlashMovie before it’s loaded?

Hi Yogi , am having n number of linkage in the library. I need to visible the symbols one by one while loading the library swf file. Is it possible?. Please give me your suggestion on this.

Leave a Reply

 

July 2008
M T W T F S S
« Jun   Aug »
 123456
78910111213
14151617181920
21222324252627
28293031  

Blog Stats

  • 94,229 hits