Skip to main content
Participant
May 3, 2011
Answered

How to trigger an event when any sound in a soundchannel completes

  • May 3, 2011
  • 1 reply
  • 671 views

I have a soundchannel, and I'm playing a lot of sounds in it, but I need the completion of any sound file within that channel to be followed by a wait of two seconds, then trigger an event. How can I do this?

This topic has been closed for replies.
Correct answer Ned Murphy

When a SoundChannel object sound is complete, there is a soundComplete event that gets dispatched (Event.SOUND_COMPLETE).  Sound assign a listener for that event.  If you need more info, the Flash help documentation has it all.

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
May 3, 2011

When a SoundChannel object sound is complete, there is a soundComplete event that gets dispatched (Event.SOUND_COMPLETE).  Sound assign a listener for that event.  If you need more info, the Flash help documentation has it all.

Participant
May 3, 2011

It does not seem to be triggering. Here's my code:

channel2.addEventListener(Event.SOUND_COMPLETE, nextHandler);

var dec:Number = 2;
var seconds:Number = 0;
var countseconds:Number = 2;

var timer:Timer = new Timer(dec*1000);
timer.addEventListener(TimerEvent.TIMER_COMPLETE, timerComplete);

function nextHandler(evt:Event){
timer.start();
trace("start");
}

function timerComplete(evt:Event){
timer.stop();
trace("Complete");
}

For the purposes of testing, I excluded the junk that used "seconds," "countseconds," etc. I'm just right now trying to get a "start" text in output, but I can't.

I must note that the sounds I play in the channel are determined by a switch statement, so creating a "sound_complete" for each of them is rather tedious and impractical.

Ned Murphy
Legend
May 3, 2011

There is nothing impractical about having listeners for anything that you need to have listeners for, tedium can usually be managed if coding is done efficiently... if you are only playing one sound at a time, you only have to assign one SOUND_COMPLETE listener at a time.

As for the event not being caught, I now recall that I also had a problem with that and I don't know how to go about resolving it, so maybe someone else will come along with some ideas.