Jump to content
Search Community

unloading a swf with FLVPlayback

justignite test
Moderator Tag

Recommended Posts

Hello. I have a problem in unloading a swf using FLVPlayback. I have a main class and I use SWFLoader in loading my swfs. One swf is using a FLVPlayback. Everything is fine except the sound of the video doesnt load. I think I can use unloadAndStop but I cannot find it in SWFLoader.

 

My other option is to use customized player using VideoLoader and not FLVPlayback. But if there are still ways to make it right with playback, im open to it.

 

Need a help. Thank you,

 

Link to comment
Share on other sites

Actually, SWFLoader automatically uses unloadAndStop() internally when available. But FLVPlayback is a tricky one because it has several bugs in it that can make it act strangely, plus it's something like 4x bigger (kb-wise) than VideoLoader. It uses NetStream which is also tricky because you must close() the NetStream before you unload the content, otherwise you can run into garbage collection issues. I suspect that if you have an FLVPlayback running/playing in a sub-swf and then you just unload the sub-swf, it won't close things adequately. 

 

It's very important that you clean up after yourself in your sub-swf before unloading it (remove event listeners, close NetStreams, etc.) - LoaderMax/SWFLoader can't do that stuff for you because it can't know what you did inside the sub-swf (creating listeners, starting NetStreams, etc.)

 

I suspect you'd get more consistent behavior (and save a bunch of kb) if you used VideoLoader instead - I had a buddy who was using FLVPlayback in a project and he ran into odd behavior and said when he switched to VideoLoader things worked great. I'm not saying that'll happen for everyone, but it might be worth a shot if you're having trouble with FLVPlayback. 

Link to comment
Share on other sites

I just want to share what is my solution to this problem. Well, it took me time to fix this (making another class for VideoLoader) but even using the VideoLoader, the problem still occurs. 

 

The problem was when you unload a sub swf from a parent swf that has a video on it, the sounds still remains. So my little solution is to put :

 

SoundMixer.stopAll(); in my unloadSWF function. T_T

Link to comment
Share on other sites

It sounds like in both scenarios you weren't closing the NetStream properly in the sub-swf. Even though the SoundMixer.stopAll() may technically be working for you in terms of stopping the sound, I suspect that the NetStream itself might be persisting, so I'd strongly recommend ensuring that you close it properly before unloading. 

 

In SWFLoader's docs, there's some sample code you can put into the sub-swf itself so that it runs a function whenever it is told to unload:

 

var curParent:DisplayObjectContainer = this.parent;
while (curParent) {
    if (curParent.hasOwnProperty("loader") && curParent.hasOwnProperty("rawContent")) {
        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...
    yourVideoLoader.dispose();
}
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...