Table of Contents

Sound.onSoundComplete( ) Event Handler Flash 6

occurs when a sound finishes playing
soundObject.onSoundComplete()

Description

The onSoundComplete( ) event handler executes when an attached or loaded sound finishes playing (i.e., when soundObject.position = = soundObject.duration). It can be used to create a playlist of sounds that play in sequence or to cue some animation that starts precisely when a sound ends. To use onSoundComplete( ), we assign it a callback function that performs the action we wish to take when our sound finishes playing. For example, the following code loads an "introduction" voiceover track. When the track is done, the menu at frame chapter1 appears:

narrative = new Sound();
narrative.attachSound("introduction");
narrative.start();
   
narrative.onSoundComplete = function () {
  // Intro's done. Display the chapter1 menu.
  _level0.gotoAndStop("chapter1");
}

Flash checks ten times per frame tick to see if the onSoundComplete( ) event should be triggered. Hence, theoretically, movies with higher frame rates have more accurate onSoundComplete( ) events.

Example

The following code displays the playback progress of a sound in the Output window:

// Create a Sound object
s = new Sound();
// Attach and play a Library sound
s.attachSound("groove");
s.start();
   
// When the sound finishes, display "done!" in the Output window
s.onSoundComplete = function () {
  trace("done!");
}
   
// Every frame, check how much of the sound has played
this.onEnterFrame = function () {
  trace("Played: " + s.position + " of " + s.duration + " milliseconds");
}

See Also

Sound.duration, Sound.onLoad( ), Sound.position


Table of Contents