My listener is... deaf

I’m trying to trigger the completeHandler function when the loader is done loading IMG1.jpg. I know the rest of the code is sound, because if I move the code from the function to the main it works.

So, what am I doing wrong?



import flash.display.Sprite;
import flash.events.Event;

var logo:Sprite = new Sprite();
var loader = new Loader();

loader.load(new URLRequest("IMG1.jpg"));
loader.addEventListener(Event.COMPLETE, completeHandler);

function completeHandler(event:Event):void {
	
logo.addChild(loader);
addChild(logo);

}

Thank you in advance guys!

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);

It kind of makes sense that you need to use a different object to keep track of the loading process, since the Loader may need to dispatch events of its own.

thank you, it worked…