Search code examples
flashbuttonactionmute

Action script 3 mute button


I have this action script code that is working perfectly but i am try to reverse the process where the movie starts without any sound, and then when you click the button the music will be unmuted.

It seems i can't figure out how to do this. Maybe some one can show me how it is done, i really know nothing about action script 3

function setMute(vol){
var sTransform:SoundTransform = new SoundTransform(0,0);
sTransform.volume = vol; SoundMixer.soundTransform = sTransform;
}
var Mute:Boolean = false;
mutebutton.addEventListener
(MouseEvent.CLICK,toggleMuteBtn);
function toggleMuteBtn(event:Event){ if(Mute){ Mute = false; setMute(1);
mutte.gotoAndStop(1); }
else{ Mute = true; 
setMute(0);
mutte.gotoAndStop(2); }
}

Thanks for the help.


Solution

    1. Change function toggleMuteBtn(event:Event) =>

      function toggleMuteBtn(event:Event = NULL)

      This allows you to call the function without triggering an Event.

    2. Use toggleMuteBtn(); anywhere you need to mute/unmute. Using it once when the application starts will set your initial state to muted instead of unmuted.