
Sound.position Property
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Alphabetical Language Reference
|
783
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 trig-
gered. 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 ...