好吧,我是一个完全新手在闪光as3,所以这必须是非常容易解决我猜。我用flash cs6录制了一个声音板,非常简单:1帧,10个按钮,每个按钮发出不同的声音。问题是这些声音的重叠,所以我需要的是当我按下一个按钮时,另一个声音停止播放。有没有人请?
发布于 2015-10-07 16:04:52
请参阅Sound类中的play()方法文档,它返回一个SoundChannel对象,该对象具有一个stop()方法。
所以你可以这样做(示意性的):
var currentChannel:SoundChannel;
button1.addEventListener(MouseEvent.CLICK, onButtonClick);
button2.addEventListener(MouseEvent.CLICK, onButtonClick);
button3.addEventListener(MouseEvent.CLICK, onButtonClick);
function onButtonClick(event:MouseEvent):void
{
/* provided you have implemented selectSoundByButton func somewhere */
const sound:Sound = selectSoundByButton(event.currentTarget);
if (currentChannel) {
currentChannel.stop();
}
currentChannel = sound.play();
}更详细的描述:
假设您想在flash中创建另一个fart按钮应用程序。这就是你要做的:
to
导入声音;var当前频道:声音频道;常量MySound:flash.media.Sound=新的声音();函数onClick(e:MouseEvent):onClick{ if ( currentChannel ) { currentChannel.stop();}currentChannel= mySound.play();} myButton.addEventListener(MouseEvent.CLICK,onClick);
发布于 2015-10-08 01:34:13
在播放声音之前,将此代码添加到每个按钮的代码中:
SoundMixer.stopAll();如果要在Adobe Flash中直接从时间轴添加动作,则不需要导入该类。如果你是在FlashDevelop或FlashBuilder之类的集成开发环境中工作,请在开头添加以下代码(在Package {之后):
import flash.media.SoundMixer;祝你编码愉快!
编辑:More info on the SoundMixer class
https://stackoverflow.com/questions/32986576
复制相似问题