0

我有点进退两难。完成播放特定声音后,我需要在 MovieClip 中调用一个函数。声音是通过我导入的外部类中的声道播放的。播放工作完美。

这是我的外部类 Sonus 的相关代码。

public var SFXPRChannel:SoundChannel = new SoundChannel;
var SFXPRfishbeg:Sound = new sfxpr_fishbeg();
var SFXPRfishmid:Sound = new sfxpr_fishmid();
var SFXPRfishend3:Sound = new sfxpr_fishend3();
var SFXPRfishend4:Sound = new sfxpr_fishend4()

public function PlayPrompt(promptname:String):void
{
    var sound:String = "SFXPR" + promptname;
    SFXPRChannel = this[sound].play();
}

这是通过文档类“osr”中的导入调用的,因此我通过“osr.Sonus.---”在我的项目中访问它

在我的项目中,我有以下代码行。

osr.Sonus.SFXPRChannel.addEventListener(Event.SOUND_COMPLETE, promptIsFinished);

function prompt():void
{
    var level = osr.Gradua.Fetch("fish", "arr_con_level");
    Wait(true);
    switch(level)
    {
        case 1:
            osr.Sonus.PlayPrompt("fishbeg");
        break;
        case 2:
            osr.Sonus.PlayPrompt("fishmid");
        break;
        case 3:
            osr.Sonus.PlayPrompt("fishend3");
        break;
        case 4:
            osr.Sonus.PlayPrompt("fishend4");
        break;
    }
}

function Wait(yesno):void
{
    gui.Wait(yesno);
}

function promptIsFinished(evt:Event):void
{
    Wait(false);
}

osr.Sonus.PlayPrompt(...) 和 gui.Wait(...) 都可以完美地工作,因为我在项目的这一部分的其他上下文中使用它们没有错误。

基本上,声音播放完毕后,我需要 Wait(false); 被调用,但事件侦听器似乎没有“听到” SOUND_COMPLETE 事件。我在某个地方犯了错误吗?

作为记录,由于我的项目结构,我无法从 Sonus 中调用适当的 Wait(...) 函数。

帮助?

4

1 回答 1

0

Event.SOUND_COMPLETE 由 sound.play() 返回的 soundChannel 对象调度。这意味着您必须先调用 sound.play()添加监听器,并且每次调用 play 后都必须显式添加监听器。

public function PlayPrompt(promptname:String):void
{
  var sound:String = "SFXPR" + promptname;
  SFXPRChannel = this[sound].play();
  SFXPRChannel.addEventListener(Event.SOUND_COMPLETE, promptIsFinished);
}

然后在 promptIsFinished 你应该删除监听器。

function promptIsFinished(evt:Event):void
{
    evt.currentTarget.removeEventListener(evt.type, promptIsFinished);
    Wait(false);
}
于 2012-03-30T23:26:57.450 回答