Here’s something the I and the other AS developer here never really grokked, although it seems like it should be super basic. :h:
I’ve got a large (2 month) project written entirely in AS3 (i.e. no IDE). Someone else has written a nice basic preloader that will load my SWF into the page.
The only problem is that it isn’t working for my SWF. I’m not getting the COMPLETE event to signal loading done – and my SWF is starting to run before it’s all loaded. Now, I assume that this is the normal behavior that I’ve just forgotten. But how, then, should one load an external SWF if one wants enough to load so that the user can interact, but not so much that the loaded SWF is already starting to do its thing w/o the user?
The preloader loads in a simple animation and then unloads it on COMPLETE.
var l:Loader = new Loader();
var ploader:PreLoader = new PreLoader();
addChild(ploader);
ploader.x = 410;
ploader.y = 140;
trace(ploader.x , ploader.y);
ploader.debug.text = "loading";
l.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loop, false, 0,true);
l.contentLoaderInfo.addEventListener(Event.COMPLETE, done, false, 0,true);
l.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, error, false, 0,true);
l.load(new URLRequest("main.swf"));
function loop(e:ProgressEvent):void
{
var perc:Number = Math.ceil((e.bytesLoaded / e.bytesTotal) * 100);
ploader.loadProgress_txt.text = perc.toString();
this.ploader.preLoaderBurst_mc.maskComp_mc.gotoAndStop(perc);
trace("perc = " + perc);
}
function done(e:Event):void
{
ploader.debug.text = e.toString();
removeChild(ploader);
ploader.loadProgress_txt = null;
addChild(l);
}
function error($error:IOErrorEvent):void {
ploader.debug.text = $error.toString();
}