1,105,371 Community Members

AS3 Sound On/Off button

Member Avatar
BlueCarNumber9
Newbie Poster
7 posts since Nov 2006
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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;
      trans.volume=0;
     SoundMixer.soundTransform = trans;
      }
      
  function onSound(e:Event) {
      musicOn = true;
      play_btn.visible = false;
      stop_btn.visible = true;
      trans.volume=1;
      SoundMixer.soundTransform = trans;
      }
Member Avatar
rajarajan07
Nearly a Posting Virtuoso
1,448 posts since May 2008
Reputation Points: 123 [?]
Q&As Helped to Solve: 242 [?]
Skill Endorsements: 3 [?]
 
0
 

Please find the attachment

Attachments SoundTest.zip (6.43KB)
Member Avatar
BlueCarNumber9
Newbie Poster
7 posts since Nov 2006
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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!

Member Avatar
rajarajan07
Nearly a Posting Virtuoso
1,448 posts since May 2008
Reputation Points: 123 [?]
Q&As Helped to Solve: 242 [?]
Skill Endorsements: 3 [?]
 
0
 

Please find the attachment in CS3 version.

Attachments SoundTest.zip (7.21KB)
Member Avatar
bobby_boer
Newbie Poster
1 post since Feb 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: