Jump to content


onChildComplete, how to get the current childs id?

Recommended Posts


I can someone help me out please?


Perheps it's very simple, but when using the parse method of LoaderMax you can't give each item an id.

The reason why is because item2 in the array can be much larger to load then item 0 or 3 so what i would like

is to check when some item is finished loading and then add it to the stage and do some tween motion with this current loaded item.


My question is, can you get an id ? or the position in the array of the current item that is loaded? so, img1.jpg = id0, card2.swf = id1, etc..


This is the code i have so far:


var containers:Array = [clip1, clip2, clip3, clip4];


private function loadMultipleItems():void {


LoaderMax.activate([imageLoader, SWFLoader]);

var urls:Array = ["img1.jpg", "card2.swf", "img3.jpg", "img4.jpg"];

var que:LoaderMax = LoaderMax.parse(urls, { maxConnection:4, onProgress:_progressHandler, onChildComplete:_childCompleteHandler}, { width:80, height:110, scaleMode:"strech"});





private function _progressHandler(event:LoaderEvent):void {

//trace("progress ", event.target.progress);



private function _childCompleteHandler(event:LoaderEvent):void {

var currentContent : ContentDisplay = event.target.content;

//can i get the event.target.id ?? where for example the id is the position in the url array?

//something like this:

var idLoaded: int = currentContent.id ;





Link to comment
Share on other sites

You can use LoaderMax's getChildIndex() method to figure out the loader's position in the queue.


var queue:LoaderMax = LoaderMax.parse(["1.jpg","2.jpg","3.jpg"], {onChildComplete:_childCompleteHandler});

private function _childCompleteHandler(event:LoaderEvent):void {
   var index:int = queue.getChildIndex(event.target as LoaderCore);
   trace(event.target + " finished, and it is in position " + index + " of the queue.");


Does that answer your question?

Link to comment
Share on other sites

Thanks, but i got an error:


Implicit coercion of value with static type Object to a possible unrelated type com.greensock.loading.core:LoaderCore


is used it like you said, var index:int = _que.getChildIndex(event.target);


What am i doing wrong? the _que is a variable setup like this:


_que = LoaderMax.parse(urls, { maxConnection:1, onProgress:_progressHandler, onComplete:_queCompleteHandler, onChildComplete:_childCompleteHandler}, { width:80, height:110, scaleMode:"strech"});


oops, i just see it, i had private var _que : LoaderMax; but it's not of that type i guess ?

Link to comment
Share on other sites

No no, sorry, I forgot to cast event.target as LoaderCore (notice in the ASDocs that getChildIndex() expects one argument that is of type LoaderCore). Flash just didn't know that event.target was a LoaderCore, so it spit out an error. So that line would look like:


_que.getChildIndex(event.target as LoaderCore);


And of course don't forget to import that class:

import com.greensock.loading.core.LoaderCore;

Link to comment
Share on other sites

Thanks :D:D It is working now !

Great class by the way!

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.