1
votes

i want to have the music always playing and the ability to mute different parts. It is for a project where you click on different people and they come to life to play music. a stop and play would not have them in snyc. I have not been using action script long

var my_sound:Sound = new Sound();
my_sound.load(new URLRequest("triumphant.mp3" ) );
function setMute(vol){
var sTransform:SoundTransform = new SoundTransform(0);
sTransform.volume = vol; 
SoundMixer.soundTransform = sTransform;
}
my_sound.play();
setMute(0)
//2.
//3.
var Mute:Boolean = true;
play_btn.addEventListener(MouseEvent.CLICK, toggleMuteBtn)
function toggleMuteBtn(event:Event) { 
if (Mute) { 
    Mute = false; 
    setMute(1);
     }
    else{ Mute = true; setMute(0 );

     }
}
1

1 Answers

5
votes

You should assign each sound to a different channel. Each channel has it's own volume and pan transformation.

SoundMixer.soundTranform is for the global sound.

var _bassSound:Sound = new Sound();
_bassSound.load(new URLRequest("you_mp3.mp3"));

var _bassChannel:SoundChannel = _bassSound.play();
_bassChannel.soundTranform = new SoundTranform(1,0);

then you could make your mute function like this

function setVolume (soundChannel:SoundChannel, volume:Number=0) {

   var transform:SoundTransform = soundChannel.soundTransform;
   transform.volume = volume;
   soundChannel.soundTransform = transform;

}

// so you call it like this

setVolume(_bassChannel);

// or if you want to unmute

setVolume(_bassChannel, 1);