Jump to content
Search Community

LoaderMax.prioritize - why it doesnt work?

deshu test
Moderator Tag

Recommended Posts

Hello, can someone tell me, why this code:

 

import com.greensock.loading.LoaderMax;
import com.greensock.loading.ImageLoader;
import com.greensock.events.LoaderEvent;
import com.greensock.loading.core.LoaderCore;



var loader1:ImageLoader = new ImageLoader("1.jpg", {name: loader1})
var loader2:ImageLoader = new ImageLoader("2.jpg", {name: loader2})

var queue:LoaderMax = new LoaderMax({maxConnections:1, onChildComplete: childComplete});

queue.append(loader1);
queue.append(loader2);
queue.load();

function childComplete(e:LoaderEvent){
var i:int = queue.getChildIndex(e.target as LoaderCore);
trace(i);
}


LoaderMax.prioritize("loader2");
loader2.prioritize(true);

 

...output is:

//0
//1

 

and not:

//1
//0

 

 

Thanks in advance!

Link to comment
Share on other sites

That is expected behavior. Remember, when you prioritize() a loader, it changes its index in any parent LoaderMax queues to which it belongs, so in this case, loader1 is index 0 and loader2 is index 1 to begin with. Then you prioritize() loader2, so it moves to index 0 and displaces loader1, moving it to index 1. When loader2 loads (which should happen first now because it's prioritized), you see the index traced out as 0.

 

This behavior is demonstrated in the main interactive demo on the http://www.greensock.com/loadermax/ page. Click on any image and you'll see the index numbers change in the corners.

 

Feel free to trace(e.target) and verify that loader2 is indeed loading first.

 

Oh, and you were missing quotes around your loader names. Like name:"loader1" instead of name:loader1. The name should always be a String.

Link to comment
Share on other sites

Ah, you are right. I feel so stupid:)

 

So, for those, who will have the same problem, theres corected code:

 

import com.greensock.loading.LoaderMax;
import com.greensock.loading.ImageLoader;
import com.greensock.loading.core.LoaderCore;
import com.greensock.events.LoaderEvent;


var loader1:ImageLoader = new ImageLoader("1.jpg", {name: "loader1"})
var loader2:ImageLoader = new ImageLoader("2.jpg", {name: "loader2"})

var queue:LoaderMax = new LoaderMax({maxConnections:1, onChildComplete: childComplete});

queue.append(loader1);
queue.append(loader2);
queue.load();

function childComplete(e:LoaderEvent){
var i:int = queue.getChildIndex(e.target as LoaderCore);
trace("index: " + i + " | url: " + e.target.url);
}

 

And here are 3 ways to prioritize loader2:

 

loader2.prioritize(true);

LoaderMax.prioritize("loader2");

LoaderMax.getLoader("loader2").prioritize();

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...