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>
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?
[...] 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.
July 9, 2008 at 9:49 am
Ulti Yogi Sir
Thanks for sharing
Hoping to keep sharing
Thanks
P