Event.SOUND_COMPLETE

Friday March 14th, 2008

Yesterday I was pulling my hair out over a swf file that refused to throw the Event.SOUND_COMPLETE event when an Mp3 finished playing. I did the usual Google search and I found a few people who had the same problem so I figured I’d share my experience.

If you look at examples online they all seem painfully simple.

SoundChannel = Sound.play();
SoundChannel.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler);

And the truth is that the above code will work, but it’s oversimplified for most situations.

More often than not, you’ll have some sort of playback controls built for your sound. Let’s suppose you have play/pause implemented. If you want to begin playing a file after it has been paused, you’d do the following:

SoundChannel = Sound.play(pausePosition, 0, SoundTransform);

And your playback will continue. The important part about this however is that when you call Sound.play() a second time, you get a second SoundChannel Object as a return value.

The result of that is that your previous Object (the one with the listener attached) is overwritten by the new Object and so it’s listener disappears too.

The lesson here is that every call to Sound.play(); returns a new SoundChannel and so every call to Sound.play() should be followed by SoundChannel.addEventListener.

Make sense?

Sharing is Caring
  • Reddit
  • Digg
  • Facebook
  • Twitter
  • del.icio.us
  • StumbleUpon

Comments

Event.SOUND_COMPLETE has 3 comments so far.

Joe Anderson said:

I am so glad I found this article! I, too was pulling my hair out thinking I was crazy not being able to get the SOUND_COMPLETE to work.

Thank you so much!

Joe

aldebaran66 said:

a tip o’ the hat! thanks for the hint! all fixed!

Ryan Flynn said:

STAR! As with other posters, was pulling my hair out on this one. Thanks for the clear explanation.

Leave a comment




* Denotes required fields. But you knew that.