Hi everyone,

I am trying to make a toggling on/off button for a looping sound using AS3. Currently it starts with the on icon showing but when pressed shows the off icon but it must be pressed again to stop the music but then shows the on icon while the music is stopped and vice versa. I also have sound on my navigation buttons that are stopped when the stop icon for the loop is pressed. How can I keep the sounds for the navigation icons to continue to play and get the on/off icons for the loop working? Any help or links to a good tutorial would be great :)

var music:Sound = new Sound(new URLRequest("music.mp3"));
var trans:SoundTransform = new SoundTransform(1, -1);
var channel:SoundChannel = music.play(0, 1000, trans);
var musicOn:Boolean = true
      play_btn.addEventListener(MouseEvent.CLICK, onSound);
      stop_btn.addEventListener(MouseEvent.CLICK, offSound);
      stop_btn.visible = false;
   function offSound(e:Event) {
      musicOn = false;
      play_btn.visible = true;
      stop_btn.visible = false;
     SoundMixer.soundTransform = trans;
  function onSound(e:Event) {
      musicOn = true;
      play_btn.visible = false;
      stop_btn.visible = true;
      SoundMixer.soundTransform = trans;

Edited by BlueCarNumber9: n/a

7 Years
Discussion Span
Last Post by bobby_boer

Thank you for responding so quickly rajarajan07! I tried to open the file but it said it was an unexpected file format. I am using CS3. Could you save it in that format? I have been searching and doing tutorials and am still stuck. I am really looking forward to see what you have done! Thank you again for your reply!


Hi rajarajan07

How is the code (AS3) when you start with the sound on first.

Like.. when you load the page the sound is playing and there is a sound off button . After clicking the sound stops and a play button appears (and vice versa).

You would really help me we with this.

Kind regards,
Bobby B

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.