Sound in Actionscript3

The movie below will let you apply what you have learned.

  1. Download the movie.
  2. Add one of the volume controls.
  3. Play the sound through the channel.
  4. Add buttons to pause, restart and continue.
  5. Add frames to the movie so that there are frames according to this formula: numFrames=fps*sound.length/1000;
  6. Trace channel.position when you click the stage while the song is playing.
  7. Use this information to add a picture of an animal to the appropriate place in the movie.
  8. Add a slider so that the user can move to any frame in the movie.
Get Adobe Flash player
Download movie
var sound:Music=new Music();
var channel:SoundChannel=new SoundChannel();
channel=sound.play();
trace(12*sound.length/1000);
sldSong.maximum=sound.length/1000;
btnMute.addEventListener(MouseEvent.CLICK, goMute);
stage.addEventListener(MouseEvent.CLICK, goClick);
sldSong.addEventListener(Event.CHANGE, goPosition);
btnMute.stop();
btnMute.buttonMode=true;
var sTransform:SoundTransform = new SoundTransform(0);

function goPosition(e:Event): void {
	channel.stop();
	channel=sound.play(sldSong.value*1000);
}

function goClick(e:MouseEvent):void {
	trace(this.currentFrame);
}

function goMute(event:MouseEvent):void
{
	sTransform.volume = 0;
	SoundMixer.soundTransform = sTransform;
}

NEXT: Class Variables in ActionScript3