PDA

View Full Version : addChild twice on an external preloaded swf



Zen08
February 28th, 2010, 09:21 AM
Hi!

I hope I'm making sense on this. But is there a way to addChild twice on a preloaded swf?

Here's my code:


stop();

import flash.net.URLRequest;
import flash.display.Loader;
import flash.events.Event;

hideEmpty();

function hideEmpty()
{
empty1_mc.visible =
empty2_mc.visible = false;
}

function showEmpty()
{
trace("show");
empty1_mc.visible =
empty2_mc.visible = true;
}

var mLoader:Loader = new Loader();
var loadernum = 0;
var mySwf:String = "";

function onCompleteHandler(loadEvent:Event)
{
trace("loader num is " + loadernum);
empty1_mc.addChild(loadEvent.currentTarget.content );
empty2_mc.addChild(loadEvent.currentTarget.content );
stopLoad();
}

function onProgressHandler(mProgress:ProgressEvent)
{
var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;
trace(percent);
}

function beginLoad()
{
mySwf = "smashermerc.swf";
var mRequest1:URLRequest = new URLRequest(mySwf);

mLoader.contentLoaderInfo.addEventListener(Event.C OMPLETE, onCompleteHandler);
mLoader.contentLoaderInfo.addEventListener(Progres sEvent.PROGRESS, onProgressHandler);
mLoader.load(mRequest1);
}

beginLoad();

function stopLoad()
{
showEmpty();
mLoader.contentLoaderInfo.removeEventListener(Even t.COMPLETE, onCompleteHandler);
mLoader.contentLoaderInfo.removeEventListener(Prog ressEvent.PROGRESS, onProgressHandler);
this.stop();
}


Hope someone can help. :D

creatify
February 28th, 2010, 12:56 PM
If the swf is an animation, no, you can't add it to two Display List objects like that. You'll have to load it a second time to create a second instance. If it's a non interactive, single frame swf that you are loading, you can draw a "copy" of that to a BitmapData instance.

Ok, that all said, there are probably some very lengthy ways to load an animated swf, and copy the frames, but you're better off loading it twice if that's the case.