好吧,我完全是Flash as3的傻瓜,所以我想这必须很容易解决。我正在制作一个用Flash CS6录制声音的音板,非常简单:1帧,十个按钮,每个按钮发出不同的声音。问题是这些声音重叠,所以我需要的是当我按下一个按钮时其他声音停止播放。有人吗?
最佳答案
请参阅 play()
类中的 Sound
方法文档,它返回一个 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中创建另一个放屁按钮应用程序。那就是你要做的:
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.events.MouseEvent;
var currentChannel:SoundChannel;
const mySound:Sound = new MySound();
function onClick(e:MouseEvent):void {
if (currentChannel) {
currentChannel.stop();
}
currentChannel = mySound.play();
}
myButton.addEventListener(MouseEvent.CLICK, onClick);
关于actionscript-3 - FLASH AS3声音重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32986576/