Jump to content


Different onComplete in same loader

Recommended Posts



I'm not so used to LoaderMax yet, and i'm wondering whats the best way to do this :


(pseudo code)


queue = new LoaderMax()










How to distinct each separate img in a single onCompleteHandler function ? Or should I use different event function ?

Whats best practice ?



Link to comment
Share on other sites

Sure, you can use the same function. Just use the LoaderEvent's target property to distinguish which loader the event pertains to. Kinda like:


var queue:LoaderMax = new LoaderMax();
queue.append( new ImageLoader("1.jpg", {name:"img1"}) );
queue.append( new ImageLoader("2.jpg", {name:"img2"}) );
queue.addEventListener(LoaderEvent.CHILD_COMPLETE, completeHandler);

function completeHandler(event:LoaderEvent):void {
   if (event.target.name == "img1") {
       //do stuff
   } else if (event.target.name == "img2") {
       //do stuff


And by the way, you could attach a COMPLETE listener to each ImageLoader directly if you wanted to instead of listening to the CHILD_COMPLETE on the LoaderMax. I just used CHILD_COMPLETE because it was less code.


Oh, and by the way, if you don't want to name the loaders, you could check if (event.target.url == "1.jpg") instead (basically use the url instead of the name). Lots of options.

Link to comment
Share on other sites

Perfect, i was missing the queue.addEventListener(LoaderEvent.CHILD_COMPLETE, completeHandler); syntax, and

trace("loadername: "+event.target.name); was returning the LoaderMax instance name (useless)


Thanks a lot !

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.