Jump to content
Search Community

Questions about LoadEvent Sequence

jrg716 test
Moderator Tag

Recommended Posts

Hi,

 

I have a question on the order in which events are being fired by LoaderMax. Specifically, when I have maxConnections set to 1, I would expect that the open and complete events would fire as each file is handled (ie. interspered within the overall progress of the loader). However, this is not what I am seeing. Here's an example:

 

_loader = new LoaderMax({name:"Loader", maxConnections:1, onProgress:loadHandler});
_loader.append(new XMLLoader("config.xml", {name:"Config", onOpen:configHandler, onComplete:configHandler, onChildOpen:configHandler, onChildComplete:configHandler}));
_loader.load();

function configHandler(e:LoaderEvent):void
{
switch(e.type)
{
	case LoaderEvent.OPEN:
	case LoaderEvent.CHILD_OPEN:
		Debug.info("File {0}", e.target.name);
		break;
	case LoaderEvent.COMPLETE:
	case LoaderEvent.CHILD_COMPLETE:
		Debug.info("Complete {0}", e.target.name);
		break;
}
}

function loadHandler(e:LoaderEvent):void
{
switch(e.type)
{
	case LoaderEvent.PROGRESS:
		Debug.info("  Progress {0}", e.target.progress);
		break;
}
}

 

In this case, I'm loading a config file with two SWF children loaders the file (Test1 and Test2). Test1.swf and Test2.swf are both the same size - approx. 600K. The Progress is begin displayed for the loader instance, so I would expect that Test1.swf would complete at about 50% progress. Here's what I actually when I execute:

 

[2011-04-15 17:16:54] INFO:    File Config
[2011-04-15 17:16:54] INFO:      Progress 0.9897727272727272
[2011-04-15 17:16:54] INFO:    File Test1
[2011-04-15 17:16:54] INFO:    File Test2
[2011-04-15 17:16:54] INFO:      Progress 0.05419404715887128
[2011-04-15 17:16:54] INFO:      Progress 0.15974745522484216
[2011-04-15 17:16:54] INFO:      Progress 0.26530086329081304
[2011-04-15 17:16:54] INFO:      Progress 0.3708542713567839
[2011-04-15 17:16:54] INFO:      Progress 0.4764076794227548
[2011-04-15 17:16:54] INFO:      Progress 0.5512355104823917
[2011-04-15 17:16:54] INFO:      Progress 0.656133055467522
[2011-04-15 17:16:54] INFO:      Progress 0.7610306004526524
[2011-04-15 17:16:54] INFO:      Progress 0.8659281454377827
[2011-04-15 17:16:54] INFO:      Progress 0.970825690422913
[2011-04-15 17:16:54] INFO:      Progress 0.9950067128613332
[2011-04-15 17:16:54] INFO:    Complete Test1
[2011-04-15 17:16:54] INFO:    Complete Test2
[2011-04-15 17:16:54] INFO:    Complete Config
[2011-04-15 17:16:54] INFO:      Progress 1

 

So my basic question is why are the open and complete events for Test1 and Test2 get fired at the beginning and end of the load - i.e. why does the complete event for Test1 not occur at approx. 50% into the load (since it accounts for about 50% of the data being loaded). I even tried simulating the download at a slow speed, but no different in the order of events. What am I missing?

 

Thanks!

Link to comment
Share on other sites

Ah yes, it looks like you might just be misunderstanding the maxConnections thing (probably my fault for not explaining it well enough in the docs). maxConnections applies on an instance-level, so if you set maxConnections on a LoaderMax instance, it will only try to load one of its children at a time. But keep in mind that one of the children may be another [nested] LoaderMax instance which has a maxConnections of 2. So that LoaderMax would load 2 of its children at a time. See what I mean?

 

If you're using XMLLoader and you're having it parses loaders inside your XML, it automatically creates a LoaderMax instance internally to which it feeds any loaders that have the load="true" attribute set (in the XML). The default maxConnections value is 2 which explains the behavior you saw. You can remedy this using either of the following ways:

 

1) Just wrap your XML loaders in a node that has its maxConnections set to 1. Kinda like this:

 



 

-OR-

 

2) Wait until I upload an updated version of XMLLoader that will recognize the "maxConnections" special property. I'm working on that now and hope to post it later today. Then you'd be able to set up your XMLLoader and just tell it a maxConnections directly.

 

Make sense now?

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