As3 sound toggle


/ Published in: ActionScript 3
Save to your folder(s)



Copy this code and paste it in your HTML
  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

You need to login to post a comment.