Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
pol

Creating a Queue for Sets of LoaderMax Queues? (Multilevel)

Recommended Posts

Hi I have a simple question. I want to load sets of SWFs that go together so I can control the priority in sets, as follows (I'm showing 2 sets, but there will actually be more):

 

set 1 (prioritized): SWF-A (prioritized), SWF-B

set 2: SWF-C (prioritized), SWF-D

 

I know how to create sets 1 and 2 in code. But I don't know how to then create a next-level (higher level) queue so that I can prioritize one set over another set dynamically? Does that make sense? Any pointers on how to code this?

 

Here is my best guess, but I'm concerned if this code below is adding the same loaders to 2 queues or is doing what I intend, or even if it is coded correctly?

 

var que1:LoaderMax = new LoaderMax({name:"Que1",onComplete:que1Complete,onError:que1Error});
  que1.append(new SWFLoader("swfA.swf",{...}));
  que1.append(new SWFLoader("swfB.swf",{...}));
  que1.prioritize("swfA",true);

var que2:LoaderMax = new LoaderMax({name:"Que2",onComplete:que2Complete,onError:que2Error});
  que2.append(new SWFLoader("swfC.swf",{...}));
  que2.append(new SWFLoader("swfD.swf",{...}));
  que2.prioritize("swfC",true);

var mainQue:LoaderMax = new LoaderMax({name:"MainQue",onComplete:mainQueComplete,onError:mainQueError});
  mainQue.append(que1); (?)
  mainQue.append(que2); (?)
  mainQue.prioritize("que1",true); (?)
  mainQue.load (?)

Link to comment
Share on other sites

Sure, you can create a parent LoaderMax that contains child LoaderMax instances so that you have total control over the flow. I noticed a few problems with your code, though:

 

1) The way you're calling prioritize() is incorrect - there is a static LoaderMax.prioritize() method that accepts 2 parameters: the first is the name or url of the loader that you want to prioritize. The second is a Boolean value that indicates whether or not the loader should immediately start loading (if not, it'll just rise to the top of any LoaderMax queues it belongs to but won't start loading). There's also an instance-level prioritize() method that accepts a single parameter - that Boolean that tells it whether or not to start loading immediately. In your example, you were passing the instance-level prioritize() two parameters (I think you confused it with the static LoaderMax.prioritize() method). So if you want to prioritize "swfA.swf", you'd do:

 

LoaderMax.prioritize("swfA.swf", false);

 

Which is the same thing as calling prioritize(false) on the loader instance itself.

 

2) You passed "true" to prioritize() which means the assets will immediately begin loading. However, it sounded like you wanted to merely set up the queue and then later have things start to load. So I suspect you'd want to set that parameter to false instead.

 

3) You should probably set the maxConnections on the parent LoaderMax to 1 (the default is 2). Remember, when you nest a LoaderMax inside another LoaderMax, that child LoaderMax is treated just like any other loader. So in your example, mainQue has 2 children (que1 and que2) so by default, when mainQue starts loading, its maxConnections will be 2 so it will load() que1 and que2 simultaneously. It sounded like you wanted them to go in sequence, so setting maxConnections to 1 would accomplish that.

 

And for the record, it's perfectly acceptable to insert/append a loader into multiple LoaderMax instances. In fact, it can be a very useful technique because you could use a master LoaderMax that has all your loaders in it, and then have a few separate LoaderMax instances that contain a subset of those loaders for the sole purpose of reporting on their progress as a whole. Like you could put loader1, loader2, loader3, and loader4 into masterQueue but then have just loader1 and loader3 in reportingQueue1 and loader2 and loader4 in reportingQueue2. Of course you could nest them accordingly as well if you prefer, but the point is that there's a lot of flexibility there. Use them however you want.

Link to comment
Share on other sites

Thank you Greensock! This is super helpful and a great explanation. Thank you for taking the time to be so thorough in your response.

 

I'm excited to try and get this code working. If I have any code issues, I may post again on this thread with my code for a bit more help.

 

In appreciation,

Pol

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