Sound Complete Not Firing (AS3)
Posted
by
JasonMc92
on Stack Overflow
See other posts from Stack Overflow
or by JasonMc92
Published on 2012-03-30T21:00:25Z
Indexed on
2012/03/30
23:29 UTC
Read the original article
Hit count: 186
I have a bit of a quandary. I need to call a function inside a MovieClip once a particular sound has finished playing. The sound is played via a sound channel in an external class which I have imported. Playback is working perfectly.
Here is the relevent code from my external class, 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();
}
This is called via an import in the document class "osr", thus I access it in my project via "osr.Sonus.---"
In my project, I have the following line of code.
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(...) and gui.Wait(...) both work perfectly, as I use them in other contexts in this part of the project without error.
Basically, after the sound finishes playing, I need Wait(false); to be called, but the event listener does not appear to be "hearing" the SOUND_COMPLETE event. Did I make a mistake somewhere?
For the record, due to my project structure, I cannot call the appropriate Wait(...) function from within Sonus.
Help?
© Stack Overflow or respective owner