Actionscript 3 如何使用combobox[AS3]播放声音和停止声音?
在此代码中,所有声音一起播放 我想在sound1播放时,sound2停止。当sound2开始播放时,sound1停止Actionscript 3 如何使用combobox[AS3]播放声音和停止声音?,actionscript-3,Actionscript 3,在此代码中,所有声音一起播放 我想在sound1播放时,sound2停止。当sound2开始播放时,sound1停止 stop(); import flash.events.Event; import flash.media.Sound; var mysound1:MYSf = new MYSf var mysound2:sounda = new sounda combobox.addItem( { label: "sound1" } ); combobox.addItem( { la
stop();
import flash.events.Event;
import flash.media.Sound;
var mysound1:MYSf = new MYSf
var mysound2:sounda = new sounda
combobox.addItem( { label: "sound1" } );
combobox.addItem( { label: "sound2" } );
combobox.addEventListener(Event.CHANGE, myq);
function myq (e:Event):void
{
if (combobox.selectedItem.label == "sound1")
{
mysound1.play();
mysound2.stop();
}
if (combobox.selectedItem.label == "sound2")
{
mysound2.play();
mysound1.stop();
}
}
您是否尝试过以下代码
function myq (e:Event):void
{
mysound1.stop();
mysound2.stop();
if (combobox.selectedItem.label == "sound1")
{
mysound1.play();
}
if (combobox.selectedItem.label == "sound2")
{
mysound2.play();
}
}
使用
声音
类无法停止声音播放。Sound
类没有stop
方法。相反,您需要使用SoundChannel
类来停止声音播放
从Adobe API文档()中:
必须将声音对象指定给SoundChannel对象,才能使用SoundChannel的stop()
方法暂停声音