Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
none

About unloading child swf

Recommended Posts

Hi greensock team. I must say that your library looks great!

 

Right now I'm testing SWFLoader and I have one doubt. I read that for better GC, is recommended to implement a method like this in the child swf.

var curParent:DisplayObjectContainer = this.parent;
while (curParent) { 
    if (curParent.hasOwnProperty("loader") && curParent.hasOwnProperty("rawContent")) { //ContentDisplay objects have "loader" and "rawContent" properties. The "loader" points to the SWFLoader. Technically it would be cleaner to say if (curParent is ContentDisplay) but that would force ContentDisplay and some core LoaderMax classes to get compiled into the child swf unnecessarily, so doing it this way keeps file size down. 
        Object(curParent).loader.addEventListener("unload", dispose, false, 0, true); 
    }
    curParent = curParent.parent;
}
...
function dispose(event:Event):void { 
    //do cleanup stuff here like removing event listeners, stopping sounds, closing NetStreams, etc... 
}

Sorry for the stupid question, but where exactly do I need to put the first part of that code (the curParent part)?

 

I suppose I can't do it in the constructor cause the parent will not be set. Do I have to listen for the ADDED_TO_STAGE event and put it there? Or maybe listen to the Event.INIT of the loaderInfo?

 

Thanks!

Link to comment
Share on other sites

Sure, you can listen for ADDED_TO_STAGE event. 

Link to comment
Share on other sites

  • 1 month later...

Hi mate, sorry for the long delay, never saw your answer!

 

So I put the unload hook in and ADDED_TO_STAGE listener then and works great!

 

But I have some related question to this, does the SwfLoader provide some kind of load event, like the unload one?

 

I see everywhere that if I put an ADDED_TO_STAGE listener, is recommended to remove it the first time is call, to avoid weak references.

 

But if I need to load and unload the same child swf multiple times, and do some kind of re-initialization and cleanup, is not clear to me how to do that, for example starting and stoping and animation in each cycle. I have the "unload" hook for doing the cleanup, but not sure how to do re-the initialization if the ADDED_TO_STAGE listener is removed.

 

An example will be something like this

1-Child SWF Load

2-ADDED_TO_STAGE call, where an animation is created, the unload hook set, and this ADDED_TO_STAGE listener removed.

3-Child SWF is unload, the unload hook gets called and stop the animation.

4-Child swf load again, but no ADDED_TO_STAGE listener to start the animation again!

 

Is there any "load" hook, like the "unload" one?

 

Hope the question is understood, thanks in advance!

Link to comment
Share on other sites

You can listen for a "COMPLETE" event - that tells you when it has finished loading.

 

You can unload() and load() as much as you want. 

Link to comment
Share on other sites

Hi Greensock, thanks for your response.

 

But isn't the complete event fired in the "parent" swf? I mean some kind of event that is fired in the child, as the "unload" event that is called when unloading the swf.

Link to comment
Share on other sites

The events are dispatched from the loader itself, not the DisplayObject/swf. 

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