Jump to content
Search Community

dispose() invokes onProgress [SOLVED]

Philip Bulley test
Moderator Tag

Recommended Posts

When calling dispose() on an instance of ContentDisplay, onProgress is subsequently invoked with a value of 1.

 

Is this intentional? And if so, how can I effectively remove the onProgress callback inside the onComplete callback?

 

Basically, I don't want onProgress to be invoked after calling dispose().

 

Thanks!! :)

Phil

 

PS. I've uploaded an example .fla of this behaviour (minus greensock.swc which should sit in the same dir as the fla).

LoaderMaxTest.zip

Link to comment
Share on other sites

That's a bit of a tricky issue because you're checking the progress of the LoaderMax instance and technically it did finish loading, so its status should be COMPLETED and therefore the progress should be 1 unless you leave the child loader in its queue (unload() instead of dispose()). But since the bytesLoaded and bytesTotal changed when the child SWFLoader was disposed, a PROGRESS event should be dispatched.

 

Your example did expose a tweak I needed to make to SWFLoader in order to make it correctly report progress as 0 after unload() was called, so I just posted an update to the platform with that change in place. So if you call unload() on your SWFLoader and then check its progress, you'll see that it's 0. But again, if you dispose() the loader, the LoaderMax instance should still technically have a progress of 1 because it finished loading and it doesn't contain any loaders that aren't loaded yet (when you dispose() the child, it is removed from the parent LoaderMax queue of course).

 

Make sense?

 

P.S. Thank you very much for putting together the sample FLA that allowed me to see very quickly and clearly what you were running into. I wish everyone did that :)

Link to comment
Share on other sites

I had to read that twice, but yes, makes perfect sense!

 

In which case, I'm wondering how I can null the onProgress callback reference once the file load is complete. That way, in theory, once the SWFLoader has completed, the reference to the onProgress callback function will be removed, and subsequently, when that loader is disposed, onProgress will not contain a function reference to invoke.

 

I've attempted this by adding the callbacks to the SWFLoader (instead of LoaderMax as I had done previously), and in the onComplete handler, I'm setting:

event.target.vars.onProgress = null;

 

Strangely, if I later call ContentDisplay.dispose(), the original onProgress handler is called. It's as if I had never nulled the callback reference. Here's another FLA demo:

LoaderMaxTest 2.zip

 

PS. And thank you, as ever, for providing the speediest and best support around!! (You and the Robotlegs guys are truly in a league of your own when it comes to this!)

Link to comment
Share on other sites

Actually, think of the vars parameter of the constructor as more like a group of configuration parameters in a more readable format - it typically doesn't do any good to alter those parameters AFTER the constructor already used them for its initial configuration. The ship has sailed. In terms of the onProgress/onComplete/etc. special properties, those just tell LoaderMax to do an addEventListener() internally for you. so, for example, if your vars object looks like this:

{onProgress:progressHandler, onComplete:completeHandler}

 

Then LoaderMax will do this internally in the constructor (once):

 

this.addEventListener(LoaderEvent.PROGRESS, progressHandler, false, 0, true);
this.addEventListener(LoaderEvent.COMPLETE, completeHandler, false, 0, true);

 

And it will also remove those event listeners automatically when you dispose() the loader. So those shortcuts are pretty convenient but you could do that stuff manually if you prefer.

 

I say all this to help you understand that if you want to remove your onProgress listener, you can simply do this:

 

myLoader.removeEventListener(LoaderEvent.PROGRESS, progressHandler);

 

(do that instead of trying to alter the vars parameter's onProgress property that you passed into the constructor)

 

Make sense?

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