Jump to content
Search Community

Deferred Loading from XML

jrg716 test
Moderator Tag

Recommended Posts

Hi,

 

I am wondering what the best approach is for handling deferred loading of subloaders specified in an XML file. Basically, I want to have a configuration file that contains references to various loaders (XML and SWF primarily). I wish to set these sub loaders to load=false, so that the requisite loaders are created, but not loaded. Then on an as needed basis I want to load individual or multiple subloaders at various points in my code - this is tied to a pre-loader progress screen. So basically, when I choose to load one or more subloaders using the .load() method, it will show the progress bar based on the combined size of the subloaders I have chosen to load at that time. Think of a multi-level game, where you want to pre-define all the assets ahead of time in a single XML, but defer loading of the necessary information until the level that it is needed.

 

My initial thought was that if I create a queue, assign the base XMLLoader (for the config) to the queue, load the XML and tie the progress bar to the PROGESS and COMPLETE events of the queue, that when I choose to trigger additional loads of the deferred subloaders, this should reactivate the queue events - since ultimately these subloaders are children of the queue. However, this doesn't seem to be the case.

 

My other thought was to collect load the XML with a XMLLoader not associated with a queue, at INIT or COMPLETE capture the subloaders to an array and then when I need to load them, append the required subloaders into a queue and load the queue.

 

Any thoughts on the best approach are appreciated...

 

-J

Link to comment
Share on other sites

Sure, there are lots of options. One thing that you might have misunderstood regarding the first approach you mentioned is that a LoaderMax won't fire a COMPLETE event if you never load() it. Kinda makes sense if you think about it :) So if it has 10 child loaders and you manually load() each one of those so that technically all the children are loaded (eventually), it still won't force the LoaderMax to dispatch a COMPLETE event because you never asked it to load(). Does that explain the issue you ran into or was there some other symptom?

 

You're welcome to use a single LoaderMax queue and keep inserting loaders into it and calling load() on it, but the down side to that is you'll either need to clean it out first with empty() or else all the child loaders that are already in there will contaminate your progress reporting. Like if 10 items are in there and fully loaded, and then you add another 3 and load(), the progress may report as being 80% loaded already (depending on the file sizes of course). It's probably cleaner to just get your loaders, append() them to a new LoaderMax instance each time you need to load a group, and then let 'er rip.

 

Remember, you can group your loaders in your XML by wrapping them in nodes and then get them by name whenever you want.

 







 

Then you can do:

 

var queue:LoaderMax = LoaderMax.getLoader("queue1");
queue.load();

 

And it'll find that "queue1" from inside your XML that loaded and it'll already be populated with its child loaders. Or you can get individual loaders by name or url too. It's super simple actually. And no need to put load="false" on all your loaders - it's false by default.

 

So when you're ready to start loading a few assets in a queue by name, it might look like:

var queue:LoaderMax = new LoaderMax();
queue.append( LoaderMax.getLoader("imageLoaderName1") );
queue.append( LoaderMax.getLoader("imageLoaderName2") );
...etc..
queue.addEventListener(LoaderEvent.COMPLETE, completeHandler);
queue.load();

 

Does that clear things up?

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