Jump to content
GreenSock

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

bulk prioritizing

Recommended Posts

Is it possible to prioritize a list of files? For example I have a page with a dozen assets loading on it in the main queue, but say I want to pause on and load the other dozen for another page? any suggestions.

Link to comment
Share on other sites

I don't have anything super advanced. are you looking for something more than just something like

 

 

page1Loader.pause();

page2Loader.load();

 

 

where page1Loader and page2Loader are unique LoaderMax instances with their own queues of files?

 

by prioritize are you referring to a more intelligent system that would automatically resume the first loader after the second loader is finished?

Link to comment
Share on other sites

Yeah I'm looking for more like an array of loads I can push to the back burner and load an array of items that belong to the a page to be viewed.

Link to comment
Share on other sites

  • 2 weeks later...

Why not just group them by putting them into distinct LoaderMax instances?

var queue1:LoaderMax = new LoaderMax();
queue1.append( ... );
queue1.append( ... );

var queue2:LoaderMax = new LoaderMax();
queue2.append( ... );
queue2.append( ... );

var parentQueue:LoaderMax = new LoaderMax();
parentQueue.append( queue1 );
parentQueue.append( queue2 );
parentQueue.load();

//then later, if you want to prioritize queue2:
queue2.prioritize();

 

Remember, LoaderMax instances can be nested as deeply as you want (put LoaderMax instances inside other ones inside other ones, etc.)

Link to comment
Share on other sites

That's genius Jack! Thank you. I am loving loadermax more each day.

Link to comment
Share on other sites

So here's a weird thing: When I do as describe above I get duplicate images loading (instead of one).

 

Here's my code:

 

var parentQueue:LoaderMax = new LoaderMax();

var QUEUE_NAME:String = "MY UNIQUE NAME HERE"
var queue:LoaderMax = new LoaderMax({name:QUEUE_NAME});
var loader:LoaderCore = LoaderMax.parse(xml.section[xml1].page[xml2].item[item1].@src.toString(), {bgColor:bk_color,container:page_mc, name:QUEUE_NAME, noCache:false,width:swfWidth, height:swfHeight, scaleMode:"proportionalInside", hAlign:"center", vAlign:"center", crop:false});

queue.append(loader)
parentQueue.append(queue)

 

if I just add the loader to the parent I get only one image loaded (not the duplicate)

Link to comment
Share on other sites

I'm confused - what's duplicated? You're saying you're getting the same image loading twice in two different places? Can you post a really simple FLA that can be published to see the problem?

Link to comment
Share on other sites

here's a link to a simple version of what I'm working on:

 

http://marcgarner.com/weblog/wp-content ... _queue.zip

 

The basic idea is for a website. There's a home page and multiple subpages. On first load the home page's assets are added to the the QUEUE, followed by the subsequent pages assets. What I'm looking for is all the assets for each page to be grouped together. So if the user clicks to a page that the assets haven't even started loading, I can tell the site to switch and prioritize the page being requested assets to load.

 

Does that make sense?

 

The example illustrates the duplicate image loading. Please let me know what you think. Thanks for your help.

 

marcfolio

Link to comment
Share on other sites

it took a little while to discern how your example illustrated items loading twice as I just saw one image with a bunch hidden behind it. It took a while even to notice the traces.

 

 

I think this chunk of code needs to be re-worked:

 

var image_array:Array = new Array("img0.jpg", "img1.png", "img2.jpg", "img3.jpg")
var second_array:Array = new Array("img0.jpg", "img1.png", "img2.jpg", "img3.jpg")

for (var i:uint = 0; i 	var QUEUE_NAME:String = "queue"+i
var queue:LoaderMax = new LoaderMax({name:QUEUE_NAME});
var loader:LoaderCore = LoaderMax.parse(image_array[i].toString(), {container:this, noCache:false, width:550, height:400, alpha:1, scaleMode:"proportionalInside", hAlign:"center", vAlign:"center", crop:false});
//var loader2:LoaderCore = LoaderMax.parse(second_array[i].toString(), {container:this, noCache:false, width:550, height:400, alpha:1, scaleMode:"proportionalInside", hAlign:"center", vAlign:"center", crop:true});
queue.append( loader );


//queue.append( loader2 );
parentQueue.append(queue)

}
parentQueue.load()

 

the big problem is how you have your queue creation code inside the loop. The idea is to have ONE queue (list of loaders) per page.

In your loop you are creating a new queue for every loader.

 

here is a rough visualization of the nesting that loop creates:

 

ParentQueue
    queue0
         loader of image0
    queue1
         loader of image1
    queue2
         loader of image2
    queue3
         loader of image4

 

//right now you're commented-out code is going to make things even messier, so I'm not going to pretend it isn't there.

 

What you ultimately want is something like this

 

ParentQueue
    queue0
         loader of image0
         loader of image1
         loader of image2
         loader of image4

     queue1
         loader of image0b
         loader of image1b
         loader of image2b
         loader of image4b

 

 

------------

 

I'm also guessing that this excessive nesting of loaders inside of queues inside of a parentQueue is causing your CHILD_OPEN events to fire/trace excessively which makes you think duplicates are loading... i really don't know.

 

 

 

the first place to start is to declare each queue (a list of loaders for each page) OUTSIDE your loop.

in each loop iteration, append the loader to the queue.

only AFTER the loop is done, append the queue to the PARENT QUEUE.

 

Also, you will want to have each queue built off its own loop through its own array assets. trying to build 2 queues in the same loop is not ever going to work well.

 

really though, if the loop is causing trouble, I would ditch it all together and manually get something working first using the exact format GreenSock suggested. Test with a few assets to see if the priority switching works AND then go back and make it more dynamic with the array/loop.

Link to comment
Share on other sites

Ok that makes sense. Thank you for the response. My model is pretty complex with XML file and figuring out everything. I appreciate you walking me through it. I think I see where I went wrong. I'll make a few edits and see if it sticks. Thanks.

Link to comment
Share on other sites

So in my example above moving the queue declaration outside of the for loop works... Bubt in my real file I can't move the queue out of the for loop.

 

I have a function that is called from a for loop and creates each individual page, and inside that function there's a "for" loop that adds all the assets to that page's loadermax instance.

 

What seems to be the problem is rather than creating a new loadermax instance and adding it to the parent queue it's duplicating it and adding all items to each queue. I guess I'm expecting to be able to create queues like you can movieclips or sprites in a loop and by giving them a unique name you can call them by name.

 

Is there anyway to have a queue created dynamically in a for statement and adding it to a parent queue?

Link to comment
Share on other sites

Basically I need to do this:

 

for (var i:Number=0; i<10 , i++){

var pageQueue:LoaderMax = new LoaderMax({name:"name"+i});

for(var j:Number = 0; j<10, j++){

var loader:LoaderCore = LoaderMax.parse( ... );

pageQueue.append( loader );

}

parentQueue.append(pageQueue)

}

 

But when doing so I get all assets from each loop added to multiple queues. And so the more files I have looping the more duplicates I get.

Link to comment
Share on other sites

you haven't displayed any code that would suggest that each page is using unique assets so there is very little i can offer as far as why the duplicates are happening.

 

the only thing I can gather is that you are building 10 "page queues" that load 10 assets.

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