AS3 - 声道不重复,但播放其他频道

时间:2012-12-23 03:20:46

标签: actionscript-3 flash

这是我的问题

在我的主舞台上,我添加了这个代码以重复声音,它在这个舞台上运行良好并且循环良好

var HP1sound:Sound = new HP_sound();

var HP_channel:SoundChannel = new SoundChannel();

function playSound():void
{
    HP_channel=HP1sound.play();
    HP_channel.addEventListener(Event.SOUND_COMPLETE, onComplete);
}

function onComplete(event:Event):void

{
    SoundChannel(event.target).removeEventListener(event.type, onComplete);
    playSound();
}
    playSound();

但是,我已将代码添加到另一个页面(并更改了所有变量)并且正确的声音正确播放了一次,但是,当它应该循环播放第一阶段的声音时。 (第2页代码如下所示)

var Crow_sound2:Sound = new Crow_sound();

var Crow_channel:SoundChannel = new SoundChannel();

function playSound2():void

{
    Crow_channel=Crow_sound2.play();

    Crow_channel.addEventListener(Event.SOUND_COMPLETE, onComplete);
}

function onComplete2(event:Event):void
{
    SoundChannel(event.target).removeEventListener(event.type, onComplete);

     playSound2();
}
 playSound2();

所以它正在播放声音playSound2重复播放playSound

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:1)

您忘记在以下行中将onComplete更改为onComplete2

Crow_channel.addEventListener(Event.SOUND_COMPLETE, onComplete);
SoundChannel(event.target).removeEventListener(event.type, onComplete);

他们应该是:

Crow_channel.addEventListener(Event.SOUND_COMPLETE, onComplete2);
SoundChannel(event.target).removeEventListener(event.type, onComplete2);
相关问题