Jump to content
Search Community

loaderComplete event referencing back to loader in queue

levantulee test
Moderator Tag

Recommended Posts

Hi all,

 

I am loading a variety of stuff through the LoaderMax that is added to its queue via queue.append().

 

Now when the loaderComplete event triggers, naturally I have the data but I want to be able know to what loader in the queue the data belongs to.

 

I know you can set a name in vars like that for example for an image loader.

queue.append(new ImageLoader(fileToLoad, {name:"photo1", estimatedBytes:2400, container:this, alpha:1}))

When I debug I do find the name of the loader photo1 under the event at event.target.content[0].name.

 

However this doesnt work for the DataLoader when I load text (haven't tried binary or variables as I don't need it yet). I just get the text string, but no name reference. Meaning I have no idea if I load several files using the DataLoader , what loader is associated with it inside of the LoaderMax queue.

 

How can I reference back to the loader via name?

 

I have several dozens of things to load, from images, sounds and text. The reason I want to do that so I can implement a callback system to pass the data back to the place where the load request came from to use the data at the right place.

 

Thanks

Lev

Link to comment
Share on other sites

Hi and welcome the GreenSock forums.

 

Sorry to hear you are having trouble. 

I can't seem to replicate the behavior you describe.

 

I have an example that loads 2 DataLoader with name properties. 

I can access the loader and the content of each loader using the name property like

 

LoaderMax.getLoader("carl") or LoaderMax.getContent("carl")

 

Here is my basic setup

 

var queue:LoaderMax = new LoaderMax({maxConnections:1, 
onComplete:queueCompleteHandler,
onChildComplete:childCompleteHandler
});

queue.append(new DataLoader ("carlData.txt", {name:"carl"}));
queue.append(new DataLoader ("billData.txt", {name:"bill"}));
queue.load();

function childCompleteHandler(event:LoaderEvent):void {
trace("\n");
trace("event: \t" + event);
trace("event.target: \t" + event.target);
trace("event.target.content: \t" + event.target.content);
trace("\n"); 
}

function queueCompleteHandler(event:LoaderEvent):void{
trace("all files have loaded");
trace("content of carl = " + LoaderMax.getContent("carl"));
trace("content of bill = " + LoaderMax.getContent("bill"));
trace("loader of carl = " + LoaderMax.getLoader("carl")); //this line is not in the zip but it works
}

I have attached my files. Be sure to compile with the latest LoaderMax files.

 

If you still have trouble, please provide a very simple example that clearly illustrates the issue. Thanks.

 

dataLoaderName_CS6.zip

Link to comment
Share on other sites

Hi Carl,

 

thanks a bunch :D this way works, but how about dynamic figuring out what the string shoud be in getContent.

 

What I can do is loop through the event.target.content array and find the name properties. The idea is that I don't need so spell out a specific name but can handle it completely dynamically. Along those line inside of a loop:

trace("content of "+ event.target.content[i].name = " + LoaderMax.getContent(event.target.content[i].name));
Link to comment
Share on other sites

I'm a little confused about in what event handler you are running a loop.

 

If you want to find content by index and name, you could do something like this

var i:int = 0;
LoaderMax.getContent(queue.getChildAt(i).name));

but if you know the index, I'm not sure why you would need the name to as this you can do things like

queue.getChildAt(i).content //get the content of the first loader in the queue
queue.getChildAt(i).name //get the name of the first loader in the queue
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.
×
×
  • Create New...