# Sound Control - bug in mute action

**URL:** <https://forum.kirupa.com/t/sound-control-bug-in-mute-action/326809>\
**Category:** flash\
**Created:** [January 13, 2012, 6:21pm UTC](https://forum.kirupa.com/t/sound-control-bug-in-mute-action/326809 "2012-01-13T18:21:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![stevie7](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@stevie7](https://forum.kirupa.com/u/stevie7)\
**Post date:** [January 13, 2012, 6:21pm UTC](https://forum.kirupa.com/t/sound-control-bug-in-mute-action/326809/1 "2012-01-13T18:21:09Z")

</div>

I am using the following code to mute sound in a flash file - basically turning the volume to 0 or 1.

It works fine until I go to a different scene. Once I load a new scene the button no longer works.

I know it will be something stupid that is causing this, however, I am too stupid to figure it out unfortunately!!

* * *

var soundOn:Boolean = true;  
onoff\_btn.addEventListener(MouseEvent.CLICK,toggleSound);  
//onoff\_btn.buttonMode = true;  
function toggleSound(e:MouseEvent)

{  
var s:SoundTransform = new SoundTransform();  
if(soundOn)  
{  
// turn sound off

s.volume=0;  
SoundMixer.soundTransform=s;  
soundOn=false;  
//onoff\_btn.gotoAndPlay(1);  
}  
else // sound is off  
{  
// turn sound back on  
s.volume=1;  
SoundMixer.soundTransform=s;  
soundOn=true;  
//onoff\_btn.gotoAndStop(1);  
}  
}
