Jump to content
Search Community

LoaderMax prioritize not working properly?

omnider test
Moderator Tag

Recommended Posts

Hi, the title probably isn't accurate, I'm pretty sure prioritize works fine, I just can't use it. I simply create a LoaderMax queue with 7 sample swfs and I want to prioritize them when you click on a button. The example can be found here : http://strikermultimedia.com/dev/loadermax/main.swf .

 

private function buttonClick(e:MouseEvent):void 
	{
		trace(e.target.name);
		LoaderMax.prioritize(e.target.name);
		//this[e.target.name + "Loader"].prioritize(true);

	}


	//----------------------INIT LOADER MAX----------------------------------------------------------------------------------
	private function InitLoaderMax():void 
	{ 
		//create a LoaderMax named "mainQueue" and set up onProgress, onComplete and onError listeners
		var queue= new LoaderMax({name:"mainQueue", onProgress:progressHandler, onComplete:completeHandler, onError:errorHandler, maxConnections:1});

		//append several loaders
		queue.append( clip1Loader=new SWFLoader("index1.swf", { name:"clip1", /*estimatedBytes:3000,*/ /*container:this, x:250,*/ autoPlay:false, onProgress:individualProgressHandler } ) );
		queue.append( clip2Loader=new SWFLoader("index2.swf", { name:"clip2", /*estimatedBytes:3000,*/ /*container:this, x:250,*/ autoPlay:false, onProgress:individualProgressHandler } ) );
		queue.append( clip3Loader=new SWFLoader("index3.swf", { name:"clip3", /*estimatedBytes:3000,*/ /*container:this, x:250,*/ autoPlay:false, onProgress:individualProgressHandler } ) );
		queue.append( clip4Loader=new SWFLoader("index4.swf", { name:"clip4", /*estimatedBytes:3000,*/ /*container:this, x:250,*/ autoPlay:false, onProgress:individualProgressHandler } ) );
		queue.append( clip5Loader=new SWFLoader("index5.swf", { name:"clip5", /*estimatedBytes:3000,*/ /*container:this, x:250,*/ autoPlay:false, onProgress:individualProgressHandler } ) );
		queue.append( clip6Loader=new SWFLoader("index6.swf", { name:"clip6", /*estimatedBytes:3000,*/ /*container:this, x:250,*/ autoPlay:false, onProgress:individualProgressHandler } ) );
		queue.append( clip7Loader=new SWFLoader("index7.swf", { name:"clip7", /*estimatedBytes:3000,*/ /*container:this, x:250,*/ autoPlay:false, onProgress:individualProgressHandler } ) );


		queue.load();
	}

 

The thing is that when I use the Chrome network profiler what happens is that once I click a button it seems that the particular swf really gets prioritized but the rest of swfs are actually still being loaded in the background. Does anyone have an explanation for this behaviour? I'm getting hopeless.

 

Thanks

Link to comment
Share on other sites

You're probably just seeing the file size audits at work which do NOT load the entire files. Since you didn't define an estimatedBytes for each one (or you commented them out), LoaderMax will automatically open up a URLStream briefly for each file to figure out the bytesTotal so that it can properly report its progress. As soon as it gets a response from the server, it closes the URLStream. You can avoid the file size audits easily: either define estimatedBytes for each loader -OR- simply set auditSize:false on your LoaderMax. There's also a static LoaderMax.defaultAuditSize that you can set to false if you want to affect the default value for all LoaderMax instances.

 

I'd recommend reading the Tips & Tricks page if you haven't already: http://www.greensock.com/loadermax-tips/

Link to comment
Share on other sites

I see, so that's why each swf gets briefly loaded and then cancelled. I was curious about that as well, but that is not what I was talking about unfortunately. For instance when I load the page and watch the network profiler only the first SWF is being loaded but when I click all seven buttons, all seven SWFs are being loaded at the same time. Although the progress listener is only handling the SWF that was clicked the last. So basically it looks like it works fine because all SWFs are being loaded in the sequence I clicked them it seems to me that cancel method (or whatever prioritize() do with the SWFs currently being loaded) doesn't get called.

Link to comment
Share on other sites

The other thing that could prevent the swf downloads from being cancelled immediately is actually something that LoaderMax does to protect you from garbage collection nightmares due to a bug in Flash - you see, if a Loader is closed before it finshes loading the first frame of the swf (inits), it can cause all sorts of trouble. Like it won't be garbage collected at all or it could allow sounds to play from the subloaded swf that were embedded in its timeline in a certain way, etc. So again, LoaderMax protects you from this by automatically managing the load for you and allowing the swf to init before it gets dumped. So if your sub-swfs are built in a way that they only have one frame and everything loads before it inits (which happens by default if your swf is only one frame long), then the behavior you described is normal and actually quite helpful.

 

So to recap, if you start loading a swf and then try to cancel() BEFORE it has loaded & initialized the first frame, it will wait just long enough to do so and then cancel. It's almost like it queues your request to cancel although it still dispatches the appropriate events and allows other stuff to proceed. In other words, that waiting around would NOT prevent your newly prioritized SWFLoader from beginning to load.

 

Make sense?

 

I realize this may seem like a problem or bug or annoyance, but it is actually one of the major benefits of using LoaderMax because it shields you from a bunch of bugs and inconsistencies in Adobe's loading classes (well over 25 of them).

Link to comment
Share on other sites

oh I see, thanks very much for the clarification. Finally got a chance to test it. I'm actually trying to implement LoaderMax within Gaia so I was a bit afraid about having the first frame of each page empty but it actually works fine.

 

By the way do you have any experience with LoaderMax in Gaia? Not 100% sure how to hook it to the Gaia loader :) If not that's fine, I'm more than grateful for the help you've given me so far

Link to comment
Share on other sites

oh I see, thanks very much for the clarification. Finally got a chance to test it. I'm actually trying to implement LoaderMax within Gaia so I was a bit afraid about having the first frame of each page empty but it actually works fine.

 

By the way do you have any experience with LoaderMax in Gaia? Not 100% sure how to hook it to the Gaia loader :) If not that's fine, I'm more than grateful for the help you've given me so far

Nope, I'm not very familiar with Gaia but I'm pretty sure folks have successfully used LoaderMax in Gaia without a problem.

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