我有一个 Flash 应用程序,某种加载外部 SWF 视频播放器的播放列表(我没有对该外部文件的代码访问权限),因此用户可以观看视频或跳到另一个视频。当用户切换到另一个视频时,将加载新的 SWF 文件。
问题:如果用户没有看完视频并跳到下一个,那么我会卸载以前的 SWF 文件(unloadAndStop()
)并加载一个新的。而且因为之前正在播放的 SWF 文件实际上并未卸载,所以它仍在后台播放(我听到两个音轨:当前的和上一个)。
I tried SoundMixer.stopAll()
调用,但实际上并没有帮助,因为背景加载以及当前视频开始播放时的声音。
有没有办法从主“加载器”应用程序解决这个问题?
有趣的是, unloadAndStop() 是针对您的具体情况而设计的。
根据文档...
Example: A SWF file that has a music track is loaded into an application.
Later, the SWF is unloaded using Loader.unload().
Though the SWF will be removed from the screen, the music will still be heard.
SOLUTION
Loader.unloadAndStop is a new addition to Action Script 3's API.
It helps developers to correctly stop and unload loaded content
using the Loader.load/loadBytes APIs.
...Flash Player recursively attempts to stop and clear as many
objects as possible (Sounds, NetStreams, EventListeners, etc.)
within the loaded SWF. This feature is especially useful
when unloading unknown 3rd party content.
这似乎完全符合你的情况!提供您的 Loader 实现
是正确的,这听起来像是 unloadAndStop() 方法中的错误。
一种替代解决方案可能是创建一个新的加载程序实例,而不是为每个视频使用相同的加载程序。
private var currentMovie:DisplayObject;
private function loadSWF(url:String ):void
{
if( currentMovie != null )
{
//stop the sound playing in the current movie
//then remove it from the display list
removeChild( currentMovie );
currentMovie = null;
}
var loader:Loader = new Loader();
//configureListeners
request.url = url;
loader.load( request , context );
}
private function onLoadComplete(event:Event):void
{
currentMovie = event.target.loader.content;
//etc...
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)