Unloading swf using the unloadAndStop() method, but video sounds remain audible

前端 未结 4 1855
眼角桃花
眼角桃花 2021-01-24 05:00

I have tried many approaches to unloading my swf, but to no avail, the video sounds within my laoded swf keep playing even once the swf has been loaded.

I have created a

4条回答
  •  青春惊慌失措
    2021-01-24 05:39

    After much research I have solved this problem. In the hope that this will make someone's life a lot easier, here was the issue:

    The unloadAndStop(); method removes any event listeners, instances, objects etc from the loaded SWF. In my case I had videos, and IF the video was still playing when the user exited (and the loaded unloaded the content) the sounds would carry on. It seems that one thing the unloadAndStop(); function does NOT do is stop all sounds.

    The solution? I attached an event listener to my loader, and after the content was successfully UNLOADED, I called the SoundMixer.stopAll(); function which ensured no sounds carried on playing! This DOES however mean that if you had ambient background sounds all along, they would stop too. You could go even further and get the current time of your ambient sounds and simply "restart" them immediately from that point in time.

    My simple vent listener looks like this:

    myloader.contentLoaderInfo.addEventListener(Event.UNLOAD, cleanUp);
    
    function cleanUp(e:Event):void{
       SoundMixer.stopAll(); //stop all sounds...
    }
    

    I trust this will help someone! It's a little "hacky" but it does the job just fine.

    Kind regards, Simon

提交回复
热议问题