Jump to content
Search Community

SWFLoader unload not working

masterkrang test
Moderator Tag

Recommended Posts

Hi, I'm trying to unload a SWFLoader, which contains a swf with some videos that may or may not be playing upon unloading. After calling the method, the video doesn't stop playing. Is there some step I may be missing?

 

I'm basically doing this:

 

mySWFLoader.unload();

 

Should I be calling mySWFLoader.content.unload() or mySWFLoader.rawContent.unload()? I've tried both of those but they don't work. Thanks for the help.

Link to comment
Share on other sites

This isn't a limitation of LoaderMax - it's a limitation of Flash. You should always clean up after yourself as a developer. If you add event listeners, make sure you remove them eventually. If you start playing a video, make sure you stop it and close the NetStream before you unload the swf. LoaderMax cannot know what code you run in your sub-swf and clean up for you.

 

You could create your own "dispose()" method in your swf that gets triggered whenever LoaderMax unloads your swf at which point you'd run your code that cleans up listeners, closes NetStreams, etc. See this thread for more info:

viewtopic.php?f=6&t=4212&p=16730#p16730

Link to comment
Share on other sites

I see what you mean, and that's exactly what I did, just create some methods in the swf's for stopping video etc and exposed them. My swf's were listening for an Event.UNLOAD and it wasn't getting fired when I called mySWFLoader.unload().

 

The reason why I though LoaderMax might take care of it is because I read on GreenSock's site

Subloaded swf files may not be properly unloaded or garbage collected if all nested MovieClips aren’t stopped first and even if they are, the swf may not unload properly. It can be particularly problematic if the child swf has audio that’s attached to the timeline as a “stream”.

 

That line sorta made me believe that it did take care of it. Also I read that LoaderMax internally uses unloadAndStop(), which apparently traverses through the swf and kills active classes, like streams and such...

 

Thanks for the response.

Link to comment
Share on other sites

That line sorta made me believe that it did take care of it. Also I read that LoaderMax internally uses unloadAndStop(), which apparently traverses through the swf and kills active classes, like streams and such...

Yeah, it's a tricky topic to explain. SWFLoader does indeed to an unloadAndStop() on swfs that were published for Flash Player 10 and later, plus it manually goes through all the nested MovieClips and calls stop() on them so that it works in FP9 too. In fact, there are a bunch of things that SWFLoader does to aid gc. But it would be impossible for it to know about all the code you ran in your sub-swf, the stage listeners, NetStreams, etc. that were created. And to be clear, unloadAndStop() does NOT traverse through the swf and kill active classes and streams - it primarily is for stopping MovieClips that are running. It doesn't close NetStreams or many other things (I wish it did).

 

Also, were you saying that you think the SWFLoader wasn't dispatching a LoaderEvent.UNLOAD event properly? Are you using the latest version? (that was a feature that was added about a month or two ago). Definitely make sure you've got the latest version. http://www.greensock.com/loadermax/

Link to comment
Share on other sites

Thanks for the reply, good to know that LoaderMax doesn't properly dispatch the UNLOAD event, that may be the problem I'm dealing with. I actually inherited this project that was started a few months ago... I tried to update this project to newest LoaderMax, but I got a lot of errors from plugin dependencies so I figure I'd better now open up that can of worms (and by that I mean not spend more than five minutes on it)... Anyways... very good info.

 

About your comment about the unloadAndStop(), I found this on gskinners site:

 

Here is the list of things that unloadAndStop does to prepare loaded SWFs for collection:

 

Stops all MovieClips

Stops all sounds playing/streaming

Stop/removes all Timer objects

Remove all global listeners for enterFrame, exitFrame, frameconstructed, activate, deactivate

Remove all stage listeners that have been created by the child.

Closes all NetConnection/NetStream

Video.attachNetStream/attachCamera(0)

Microphone.setLoopback(0)

Removes AS3 fonts from the global font table

Stops sockets, xmlsockets, filereference downloads, other downloading objects (grandchildren SWF), etc.

Frees bitmap related to cacheAsBitmap/filter, etc.

 

Note that all of the above are run recursively, so they will also apply to any nested children, including other loaded SWFs.

 

 

I'm not sure if this info is correct or not, all I know is that I couldn't get it to work... Will definitely be using the new LoaderMax next time.

Link to comment
Share on other sites

Well the list of things that it's SUPPOSED to do and what it ACTUALLY does are sometimes quite different as I've found many times with Adobe's stuff. Not to knock them too much - they've put together an amazing product. I'm just saying that I've run into a LOT of things that don't work as they should in Flash and this sounds like another one.

 

Are you publishing to Flash Player 10? Keep in mind that if you're not, then there is no such thing as unloadAndStop(). That's FP10 and later only.

 

And by the way, I wasn't saying that SWFLoader wasn't dispatching the UNLOAD event properly - I was asking you if that's what you were saying. I am not aware of any bugs in LoaderMax at this point, and I've tested the UNLOAD event dispatching and it seems to work just fine. Let me know if it's not working for you, though. And make sure you're setting up your listener on the SWFLoader instance properly as indicated in that thread I linked to.

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