- onSoundComplete() is a handler that executes when a sound finishes playing.
- position tells us how much of a sound has played so far
- duration tells us how long a sound is in total
// Stop the movie
stop();
// Create a sound object.
s = new Sound();
// Attach and play a library sound.
s.attachSound("groove");
s.start();
// When the sound finishes, go to the frame "soundDone"
s.onSoundComplete = function () {
trace("done!");
gotoAndStop("soundDone");
}
// Create a text field to show sound length.
this.createTextField("dur", 1, 100, 100, 200, 30);
dur.border = true;
dur.setNewTextFormat(new TextFormat("Arial", 20));
// Show sound length.
dur.text = s.duration;
// Create a text field to show sound position.
this.createTextField("pos", 2, 100, 150, 200, 30);
pos.border = true;
pos.setNewTextFormat(dur.getNewTextFormat()); // handy, eh?
// Every frame, display how much of the sound has played.
this.onEnterFrame = function () {
pos.text = s.position;
}