Jump to content
GreenSock

aaseb

progress of an element in the queue

Recommended Posts

Hi, I'm just starting with loadermax and trying to figure it out.

I'd like to know when you load a queue, is there a way to get the progress of an element in the queue rather than the overall progress?

Link to comment
Share on other sites

Absolutely. LoaderMax is built in a very object-oriented manner (more so than many other loading systems out there). Every loader has a "progress" property which you can check anytime. For example:

 

var queue:LoaderMax = new LoaderMax();
var image1:ImageLoader = new ImageLoader("1.jpg");
var image2:ImageLoader = new ImageLoader("2.jpg");
queue.append(image1);
queue.append(image2);
queue.load();

//then, to check image1's progress, you can do:
trace(image1.progress);

//and to check the overall loading progress of the queue, do:
trace(queue.progress);

 

You can define individual onProgress handlers if you prefer as well using normal addEventListener(LoaderEvent.PROGRESS, myFunction) or the "onProgress" shortcut which does the same thing in a quicker way:

 

var queue:LoaderMax = new LoaderMax({onProgress:overallProgress});
queue.append( new ImageLoader("1.jpg", {name:"img1", onProgress:img1Progress}) );
queue.append( new ImageLoader("1.jpg", {name:"img2"}) );
queue.load();

function overallProgress(event:LoaderEvent):void {
   trace("overall progress: " + event.target.progress);
}

function img1Progress(event:LoaderEvent):void {
   trace("img1 progress: " + event.target.progress);
}

 

You could even listen for CHILD_PROGRESS events on the LoaderMax queue and check the event's "target" to discern which particular child loader dispatched that event. Most events bubble up through the hierarchy too, so if you have an ImageLoader inside a LoaderMax which is nested inside another LoaderMax, you can listen for events on the parent LoaderMax and get notified about what happened with loaders that are nested deep down. The event system was built to be very robust, so if you're having trouble getting the info you need, just let me know and I'll tell you how to get it.

Link to comment
Share on other sites

very nice.

Thank you so much for your work.

Link to comment
Share on other sites

if i could get a little bit more help?...

 

I now load several swf files like so :

 

var queue:LoaderMax = new LoaderMax({name:"mainQueue", onProgress:progressHandler, onComplete:completeHandler, onError:errorHandler});

var child1:SWFLoader = new SWFLoader("child1.swf", {name:"childClip1", estimatedBytes:3000000, autoPlay:false});
var child2:SWFLoader = new SWFLoader("child2.swf", {name:"childClip2", estimatedBytes:3000000, autoPlay:false});
var child3:SWFLoader = new SWFLoader("child3.swf", {name:"childClip3", estimatedBytes:3000000, autoPlay:false});
var child4:SWFLoader = new SWFLoader("child4.swf", {name:"childClip4", estimatedBytes:3000000, autoPlay:false});
var child5:SWFLoader = new SWFLoader("child5.swf", {name:"childClip5", estimatedBytes:3000000, autoPlay:false});

//append several loaders
queue.append(child1);
queue.append(child2);
queue.append(child3);
queue.append(child4);
queue.append(child5);

queue.load();

 

when i want one of the swf to show, i load it like this (after i checked to see if it was fully downloaded):

 

mycontainer.addChild(child1.content);
LoaderMax.getContent("childClip1").rawContent.gotoAndPlay(1);

 

up to here everything works fine but i can't seem to find the right code to unload this swf and switch to a different one.

I'd like the file to remain in the cache but to free system memory when removed. I tried LoaderMax.getContent("childClip1").unload(); but when i load the swf again it doesn't play. I can see it's there because if i right click and say play then i can see it playing.

Link to comment
Share on other sites

You meant getLoader(), not getContent(), right?

 

BAD: LoaderMax.getContent("childClip1").unload();

GOOD: LoaderMax.getLoader("childClip1").unload();

 

And when you load() again, it doesn't play because you set autoPlay on your SWFLoader to false. Feel free to set it to true or just call play() on the rawContent whenever you're ready.

Link to comment
Share on other sites

It is now working with unload but i still have memory usage issues.

I tried using application domain but no luck.

 

I now have this :

 

var _newDomain1:ApplicationDomain =  new ApplicationDomain();   
var _appContext1:LoaderContext = new LoaderContext(false, _newDomain1);
var _newDomain2:ApplicationDomain =  new ApplicationDomain();   
var _appContext2:LoaderContext = new LoaderContext(false, _newDomain2);

var queue:LoaderMax = new LoaderMax({name:"mainQueue", onProgress:progressHandler, onComplete:completeHandler, onError:errorHandler});
var child1:SWFLoader = new SWFLoader("child1.swf", {name:"childClip1", estimatedBytes:3000000, autoPlay:false, context:_appContext1});
var child2:SWFLoader = new SWFLoader("child2.swf", {name:"childClip2", estimatedBytes:3000000, autoPlay:false, context:_appContext2});

 

after child1 has been loaded i call this to load child 2

 

LoaderMax.getLoader("childClip1").unload();
	child1=null;
	_appContext1=null;
	_newDomain1 = null;

	_newDomain1 =  new ApplicationDomain(); 
	_appContext1 = new LoaderContext(false, _newDomain1);
	child1 = new SWFLoader("child1.swf", {name:"childClip1", estimatedBytes:3000000, autoPlay:false, context:_appContext1});
mycontainer.addChild(child2.content);

 

and do the opposite to go back to child1 but switching from one to the other keeps increasing the memory load.

Maybe this should be the start of a new topic...

I ran into this same problem without using loadermax and I think using application domain was part of the solution. unloadAndStop() was another part but I think that doesn't work with loadermax.

 

Just to test, I added a loop with a trace in the movie that is loaded and the trace keeps coming even after unloading it.

Link to comment
Share on other sites

It sounds like you didn't clean up after yourself in your subloaded swf. LoaderMax cannot possibly know all the code you run in the sub-swf, so it can't remove event listeners that you added to the stage or NetStreams or other stuff that could create ties to memory there. See this thread for some tips: viewtopic.php?f=6&t=4212&p=16730#p16730

 

It looked like there were several typos in your code where you typed child1 but I think you meant child2, right?

 

And for the record, yes, SWFLoader does indeed use unloadAndStop() internally on the Loader instance (as long as it's available - in FP10 and later)

Link to comment
Share on other sites

I'm confused. I think I'll start a new topic when I find where the problem is really coming from (if I cant find the solution on my own)

One thing I noticed though if on the first frame of the loaded SWFs there is a movieclip with a trace inside. The trace will come when you load the queue and before any of the SWFs have been added to the stage, and that even with the autoplay property set to false. Is there any way to tell flash to load those SWFs in the cache only and not start reading anything from them?

Link to comment
Share on other sites

Right, a swf's first frame will always be read and any ActionScript there will be executed regardless of whether or not autoPlay is true - that's a Flash limitation and has nothing to do with LoaderMax/SWFLoader. However, you could just use a DataLoader and set the format special property to "binary". Then use an onComplete to dispose(true) the loader. That will effectively load the swf without caring about what kind of file it really is (ignoring any ActionScript in it) and then dump it from memory (but it should stay in the cache).

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