Hi guys,
I’ve created a preloader with an external swf loading and i wanna know what do you think about.
This is the code that almost everyone use for preloading an external file:
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
loader.load(new URLRequest("prova.swf"));
function progressHandler(event:ProgressEvent):void
{
var ratio:Number = event.bytesLoaded / event.bytesTotal;
percent.text = Math.ceil(ratio*100).toString();
bar.scaleX = ratio;
}
function completeHandler(event:Event):void{
removeChild(percent);
removeChild(bar);
percent = null;
bar = null;
addChild(loader);
}
This is the code on the first frame of the loaded swf:
stop();
//addChild(rect);
this.addEventListener(Event.ADDED_TO_STAGE, msdw);
rect.addEventListener(Event.ADDED_TO_STAGE, init);
function init(e:Event){
rect.x = stage.stageWidth / 2;
rect.y = stage.stageHeight / 2;
}
function msdw(e:Event){
stage.addEventListener(Event.RESIZE, fctres);
}
function fctres(e:Event){
rect.height = stage.stageHeight;
}
What do you think? With this i don’t have the annoying 1009 error.
Another question. If i run the swf that the preload load (sorry for the spelling )
it seems that the:
this.addEventListener(Event.ADDED_TO_STAGE, msdw);
listener isn’t called. Is it right? It’s because when i run the swf the main clip that i refer with “this” it’s added to the stage yet? but in the preloader it doesn’t?
I think i’ve been clear. I wait for your answers