/10/ sound tools: onSoundComplete(), position, duration

// 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;
}