13.8. Performing Actions When a Sound Ends
Problem
You want to perform certain actions when a sound finishes playing.
Solution
Define an onSoundComplete( ) method
for the Sound object.
Discussion
The Sound class has a built-in event that
triggers the onSoundComplete( ) method for a
Sound object when the sound finishes playing.
This is a convenient place to perform actions when the sound ends.
All you need to do is define the onSoundComplete(
) method and Flash will automatically invoke it at the
correct time:
mySound_sound.onSoundComplete = function ( ) {
trace("The sound has finished playing.");
};The onSoundComplete( ) method is invoked only
when the end of the sound is reached. It is not invoked when the
sound is stopped by way of ActionScript. Also,
onSoundComplete( ) is invoked only when the last
loop completes, not each time the sound loops, when a
sound’s playback is looped.
See Also
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access