4 Replies Latest reply on Jul 11, 2010 2:13 PM by WayneRowlands

    Flash mute/unmute button


      I have just installed Flash Professional CS5. I have set up a short 3 second Flash .swf file and incorporated it into my website using Dreamweaver CS5. The Flash file has a background sound file and the Flash program loops. I see how to set up a mute button and have done that, yet when the file loops the sound begins again. I have looked through the many tutorials and forums and simply cannot find out how to set up the button so that when the "Mute Sound" button is clicked the sound stops even after the file loops. I am guessing it might have something to do with setting up my timelines, yet I have played around with that and did not get anywhere. I am new to developing Flash. Thanks for your help, Wayne

        • 1. Re: Flash mute/unmute button
          Andrei1 Level 6

          Is sound embedded into timeline? How do you mute it? Show code related to it.

          • 2. Re: Flash mute/unmute button
            WayneRowlands Level 1

            I have embeded the sound into the timeline. I have then added a mute sound button. Attached to that button is the following code:




            • 3. Re: Flash mute/unmute button
              Andrei1 Level 6

              You are not muting but stopping sound. I guess you have to keep a reference to whether it is stopped and if it is - stop it every time first frame is executed.


              I did not check it working but here is the concept:


              // sound preference
              var playSound:String;
              if(!playSound) playSound = "play";
              if(playSound == "stop") stopSound();
              button.addEventListener(MouseEvent.CLICK, stopSound);
              function stopSound(e:MouseEvent = null):void {
                   playSound = "stop";

              Or, perhaps, better yet you set volume:


              // sound volume
              var volume:SoundTransform;
              if(!volume) volume = new SoundTransform(1);
              button.addEventListener(MouseEvent.CLICK, toggleSound);
              function toggleSound(e:MouseEvent):void {
                   volume.volume = volume.volume == 1 ? 0 : 1;
                   SoundMixer.soundTransform = volume;
              • 4. Re: Flash mute/unmute button
                WayneRowlands Level 1

                Thank you. This worked well.