Sound in Actionscript3

You can control the volume of a sound with the SoundTransform Class.

The movie below lets you control the volume two ways:

  1. The mute button simply toggles between a volume of 0 and 1.
  2. The slider lets you select a volume from 0.00 to 1.00.
Get Adobe Flash player
Download movie
var sound:Music=new Music(); //Music is the name of the mp3 in the library
var sTransform:SoundTransform = new SoundTransform(0);
sldVolume.addEventListener(Event.CHANGE,goVolume);
btnMute.stop();
btnMute.addEventListener(MouseEvent.CLICK,goMute);
sTransform.volume = 0.50; //50%
SoundMixer.soundTransform = sTransform;	
sound.play();

function goMute(e:MouseEvent):void {
  if(btnMute.currentFrame==1) {
    btnMute.gotoAndStop(2);
    sTransform.volume = 0;
  } //already muted
  else {
    btnMute.gotoAndStop(1);
    sTransform.volume = 1;
  } //mute
  SoundMixer.soundTransform = sTransform;
} //goMute

function goVolume(e:Event):void {
  sTransform.volume = sldVolume.value/100;
  lblVolume.text==""+sTransform.volume+"%";
  SoundMixer.soundTransform = sTransform;	
} //goVolume

NEXT: Start and stop a sound with the channel