Jump to content
Search Community

Understanding LoaderMax

bartpop test
Moderator Tag

Recommended Posts

I'm setting up an application using LoaderMax and can't quite seem to get things working quite properly. I'm hoping someone can answer a few questions for me.

 

In my base.swf I created a LoaderMax instance called _baseLoader. I then appended a SWFLoader to _baseLoader to load "container.swf" and initiated the load. I've got a progress bar set up to monitor the progress of _baseLoader using event.target.progress.

 

In my container.swf file I have a VideoLoader with "requireWithRoot:this.root" and a SWFLoader with "requireWithRoot:this.root".

 

When I run my app, my _baseLoader progress bar runs three times before firing the onComplete handler. In other words, it seems to be tracking the progress of each load separately instead of bundling them together. The Complete event only fires once, but the progress value runs up and down the spectrum from 0 to 1 a couple of times before the complete event fires.

 

Obviously I'm misunderstanding something. I've been through the Documentation and the demo files but would love a solid explanation of LoaderMax basics. I'm coming over from BulkLoader and this seems to be a different approach. Thanks.

Link to comment
Share on other sites

Well, I got part of my issue sorted out and I think I've got an explanation on the other part.

 

The SWFLoader I've set up in container.swf dynamically determines which swf file it will be loading when it's added to the display object. That file hasn't been defined yet when the LoaderMax object "looks ahead" for other loader objects. I included an estimated bytes figure in the SWFLoader call, (and an auditSize to increase the accuracy when it gets called later), can you tell me if LoaderMax will factor the estimated byte size into the total load estimate if the file path is being defined dynamically?

 

I hope that makes sense.

Link to comment
Share on other sites

Here's a question that has arisen out of this scenario. I'm wondering if LoaderMax calculates the total load using only Loaders that are appended directly to the LoaderMax object.

 

Here's a scenario: I've created a LoaderMax instance named "mainQueue" and appended several SWF loaders to it to load some external SWFs. One of those SWF files contains a VideoLoader that was created directly (not appended to the "mainQueue" LoaderMax object), but contains "requireWithRoot:this.root" and "estimatedBytes" parameters. When LoaderMax looks ahead to calculate the child loads, will it include this VideoLoader object, or does it ONLY look for objects appended to the LoaderMax object?

 

I'm still getting some funky preloader behavior and trying to wrap my head around what might be causing the issue.

 

Thanks!

Link to comment
Share on other sites

Here's a scenario: I've created a LoaderMax instance named "mainQueue" and appended several SWF loaders to it to load some external SWFs. One of those SWF files contains a VideoLoader that was created directly (not appended to the "mainQueue" LoaderMax object), but contains "requireWithRoot:this.root" and "estimatedBytes" parameters. When LoaderMax looks ahead to calculate the child loads, will it include this VideoLoader object, or does it ONLY look for objects appended to the LoaderMax object?

 

Yes, when SWFLoader receives the subloading swf's INIT event, it will look for any LoaderMax-related loaders INSIDE that swf (like your VideoLoader) that has its requireWithRoot set to that swf's root (sounds like you did that) and it will incorporate its progress into the SWFLoader's overall loading progress. So yes, it sounds like you set things up properly but if you're running into odd behavior, please describe what's happening. Better yet, if you could post an example FLA that demonstrates the issue, that'd be fantastic. Did you make sure your estimatedBytes on that VideoLoader is relatively accurate?

 

Oh, and make sure you've got the latest version of the classes. http://www.LoaderMax.com

Link to comment
Share on other sites

I managed to determine the cause of the odd behavior. It came down to the misuse of one little parameter.

 

I had set up a base class to preload my application SWFs but when I created my SWFLoader instances, I included the parameter "container:this" in the Loader object calls. I've come to realize that including the "container" parameter tells LoaderMax to add the loaded object to the display list as soon as the object finishes loading; in other words it essentially says for that loader: onComplete {this.addChild(content)}.

 

I handle adding all of the child objects elsewhere in my code so I really just want to hold the loaded objects in the LoaderMax object until I'm ready to add them. By including the "container" parameter I had created a sort of loop in my preloader, where objects were being added to the display list before the LoaderMax onComplete had fired.

 

Once I figured this out, I removed the "container" parameters and everything worked great. I'm starting to understand how LoaderMax works. One thing that would be helpful would be knowing how to trace out the name of the Loader object that is currently loading in the LoaderMax object.

Link to comment
Share on other sites

One thing that would be helpful would be knowing how to trace out the name of the Loader object that is currently loading in the LoaderMax object.

 

Sure. Keep in mind, though, that there can be more than one child loading at a time in a LoaderMax. By default, maxConnections is 2, so it will try to load 2 things at a time (to speed things up). Anyway, to sense when it starts loading something new, you can simply do:

 

queue.addEventListener(LoaderEvent.CHILD_OPEN, childOpenHandler);
function childOpenHandler(event:LoaderEvent):void {
   trace("started loading " + event.target.name);
}

 

Or just use the onChildOpen special property of your LoaderMax to have it set up the listener for you.

 

Does that answer your question?

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