# A preloader Advise

**URL:** <https://forum.kirupa.com/t/a-preloader-advise/307686>\
**Category:** flash\
**Created:** [April 8, 2010, 10:21am UTC](https://forum.kirupa.com/t/a-preloader-advise/307686 "2010-04-08T10:21:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![LS05](https://avatars.discourse-cdn.com/v4/letter/l/e19b73/32.png) [@LS05](https://forum.kirupa.com/u/LS05)\
**Post date:** [April 8, 2010, 10:21am UTC](https://forum.kirupa.com/t/a-preloader-advise/307686/1 "2010-04-08T10:21:47Z")

</div>

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:

```auto
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:

```auto
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:

```auto
 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 🙂
