Actionscript 3 声音完全未触发(AS3)
我有点困惑。一旦某个特定的声音播放完毕,我需要调用MovieClip中的函数。声音是通过我导入的外部类中的声音通道播放的。播放效果很好 这是我的外部类Sonus的相关代码Actionscript 3 声音完全未触发(AS3),actionscript-3,flash,actionscript,addeventlistener,flash-cs5.5,Actionscript 3,Flash,Actionscript,Addeventlistener,Flash Cs5.5,我有点困惑。一旦某个特定的声音播放完毕,我需要调用MovieClip中的函数。声音是通过我导入的外部类中的声音通道播放的。播放效果很好 这是我的外部类Sonus的相关代码 public var SFXPRChannel:SoundChannel = new SoundChannel; var SFXPRfishbeg:Sound = new sfxpr_fishbeg(); var SFXPRfishmid:Sound = new sfxpr_fishmid(); var SFXPRfishen
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(…)都工作得很好,因为我在项目这一部分的其他上下文中使用它们时没有错误
基本上,在声音播放完毕后,我需要等待(false);被调用,但事件侦听器似乎没有“听到”完成事件的声音。我在什么地方出错了吗
作为记录,由于我的项目结构,我无法从Sonus内部调用适当的Wait(…)函数
帮助?Event.SOUND\u 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);
}
不幸的是,正如我所说,我不能从索努斯内部调用Wait(false)。我想我将不得不自己在项目本身中使用类似的函数来实现这一点。尽管如此,还是谢谢你。你不一定非得这么做。您正在switch语句中调用PlayPrompt,您也可以从该范围访问SFXPRChannel,因此您可以在switch语句中调用PlayPrompt,然后在开关执行后立即添加侦听器。不,因为我的项目是这样设置的,这些片段在电影唇中隐藏,必要时在舞台上展示。每一个都有一个“gui”对象,其中包含Wait(false)所指的函数。我无法确定在任何给定点的哪个movieclip将成为等待(错误)信号的目标,因此,问题就来了。不过谢谢你。