Share Posted February 11, 2011 Hi I'm not so used to LoaderMax yet, and i'm wondering whats the best way to do this : (pseudo code) queue = new LoaderMax() queue.append(name:"img1") queue.append(name:"img2") onCompleteHandler(e){ if(img1) ... if(img2) ... How to distinct each separate img in a single onCompleteHandler function ? Or should I use different event function ? Whats best practice ? Thanks Link to comment Share on other sites More sharing options...
Share Posted February 11, 2011 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); queue.load(); 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 More sharing options...
Author Share Posted February 11, 2011 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now