如何使用AS3停止声音)

时间:2016-11-04 03:45:52

标签: actionscript-3

  

我的声音在代码中声音sound1,sound2我的声音在课堂上叫声音,声音我希望找到答案来解决我的问题。

    import flash.events.Event;
import flash.media.Sound;
import flash.media.SoundChannel;

stop();

var sound1:sounda = new sounda();
var sound2:soundb = new soundb();

cbox.addItem( { label: "chose"} )
cbox.addItem( { label: "first"} )
cbox.addItem( { label: "sec"}   )

cbox.addEventListener(Event.CHANGE,plays);

function plays(e:Event):void
{
    if (cbox.selectedItem.label == "first") 
    {
        sound1.play();
           //not working
        sound2.stop();
    } 




    if (cbox.selectedItem.label == "sec") 

    {
        sound2.play();
        //not working
        sound1.stop();
    }
    }

//当我播放sound1然后播放sound2 .. sound1仍在播放时

1 个答案:

答案 0 :(得分:1)

停止播放所有声音

import flash.media.SoundMixer;
SoundMixer.stopAll();

要停止一个声音,您必须使用SoundChannel

import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.URLLoader;
var mySound:Sound = new Sound();
var myChannel:SoundChannel = new SoundChannel();
mySound.load(new URLRequest("myFavSong.mp3"));
myChannel = mySound.play();

// ...

myChannel.stop();
相关问题