Posted By

kinski on 12/09/09


Tagged


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

sharabh
jhoard
ClayVillage
tspitzr
pepperpunk


As3 sound toggle


 / Published in: ActionScript 3
 

  1. var soundOn:Boolean = true;
  2. onoff_btn.addEventListener(MouseEvent.CLICK,toggleSound);
  3. onoff_btn.buttonMode = true;
  4. function toggleSound(e:MouseEvent)
  5. {
  6. if(soundOn)
  7. {
  8. // turn sound off
  9. var s:SoundTransform = new SoundTransform();
  10. s.volume=0;
  11. SoundMixer.soundTransform=s;
  12. onoff_btn.gotoAndPlay(1);
  13. }
  14. else // sound is off
  15. {
  16. // turn sound back on
  17. s.volume=1;
  18. SoundMixer.soundTransform=s;
  19. onoff_btn.gotoAndStop(1);
  20. }
  21. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: JaaQ on June 18, 2011

this wont work since your variable "s" is defined in the first if statement

You need to login to post a comment.