Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 如何使用combobox[AS3]播放声音和停止声音?_Actionscript 3 - Fatal编程技术网

Actionscript 3 如何使用combobox[AS3]播放声音和停止声音?

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

在此代码中,所有声音一起播放

我想在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( { 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()
方法暂停声音