本文介绍了从JavaScript事件中停止Flash中的音乐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试停止页面中已加载的Flash SWF文件中的音乐

I am attempting to stop the music inside of my flash swf that I have loaded in the page

<object id="FlashControl1" type="application/x-shockwave-flash"
data="Flash/Preloader%20-%20Splash.swf" width="980px" height="316px">
<param name="movie" value="Flash/Preloader%20-%20Splash.swf" />
<param name="wmode" value="Transparent" />
<param name="quality" value="High" />
<param name="play" value="True" />
<param name="loop" value="False" />
<param name="menu" value="False" />
<param name="scale" value="Exactfit" />
<param name="flashvars" value="name="FlashControl1"" />
<img src="Images/Banner/Main_Banner.jpg" alt="" width="980px" height="316px" />
</object>

我有一个按钮,用于加载带有Silverlight视频的模式弹出窗口,我希望通过执行SoundMixer.stop()来停止音频.命令.

I have a button that loads a modal popup with a silverlight video and I would like the audio to stop by execuding the SoundMixer.stop(); command.

我尚未在Google上找到解决方案

I have yet to find a solution on google

推荐答案

在Flash文件中,您必须具有以下功能:

In your Flash file, you must have the following function:

function stopSound():void {
    SoundMixer.stop();
}

然后,您必须使其可用于JavaScript调用

Then, you must make it available for JavaScript calls

ExternalInterface.addCallback('stopSound', stopSound);

在JavaScript代码中,您必须具有以下用于选择swf的简单函数:

In your JavaScript code you must have this simple function that selects your swf:

function getFlashMovie(movieName) 
{
    var isIE = navigator.appName.indexOf("Microsoft") != -1;
    return (isIE) ? window[movieName] : document[movieName];
}

当您想停止电影中的声音时,只需从JavaScript调用以前在swf中可用的功能即可:

And when you want to stop the sounds in your movie, you just call the function you've previously made available in the swf, from JavaScript:

movie = getFlashMovie('your-movie-name');
movie.stopSound();

应该这样做.有关ExternalInterface.addCallback的详细信息,请查看Adobe AS3语言参考页面.

That should do it. For more info on ExternalInterface.addCallback, check out the Adobe AS3 Language Refrence page.

这篇关于从JavaScript事件中停止Flash中的音乐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 23:44