2 Replies Latest reply on Jan 13, 2011 7:36 AM by Macnimation

    Stop audio when you roll off a button?

    Macnimation Level 1

      I have a button that when the user rolls over it, it plays a 3 second piece of audio.

       

      that works fine.

       

      When the user rolls off though, the audio still plays, that, if the user rolls over the button several times you get multiple instances of the auduo until they all play out.

       

      Is there a way to cut off the audio on roll off?

       

      cheers

        • 1. Re: Stop audio when you roll off a button?
          yalp.com.br Level 1

          You can create a function to turn the volume down when the mouse goes off the button and back up when it goes over again...

           

           

          var volTransform:SoundTransform=SoundMixer.soundTransform;

           

          buttonInstance.addEventListener(MouseEvent.MOUSE_OUT, muteVolume);

           

          function muteVolume(e:MouseEvent):void{
              volTransform.volume=0; //mutes sound
              SoundMixer.soundTransform=volTransform;
          }

           


          buttonInstance.addEventListener(MouseEvent.MOUSE_OVER, upVolume);

           

          function upVolume(evt:MouseEvent):void{
              volTransform.volume=1;
              SoundMixer.soundTransform=volTransform;
          }

          • 2. Re: Stop audio when you roll off a button?
            Macnimation Level 1

            Hi,

             

            thanks, that worked a treat.

             

            To reduce the code for multiple buttons I edited your code as this:

             

             

            var volTransform:SoundTransform=SoundMixer.soundTransform;

             

            buttonName1.addEventListener(MouseEvent.MOUSE_OUT, muteVolume);

            buttonName2.addEventListener(MouseEvent.MOUSE_OUT, muteVolume);

            buttonName3.addEventListener(MouseEvent.MOUSE_OUT, muteVolume);

             

            function muteVolume(e:MouseEvent):void{
                volTransform.volume=0; //mutes sound
                SoundMixer.soundTransform=volTransform;
            }

             


            buttonName1.addEventListener(MouseEvent.MOUSE_OVER, upVolume);

            buttonName2.addEventListener(MouseEvent.MOUSE_OVER, upVolume);

            buttonName3.addEventListener(MouseEvent.MOUSE_OVER, upVolume);

             

            function upVolume(evt:MouseEvent):void{
                volTransform.volume=1;
                SoundMixer.soundTransform=volTransform;
            }

             

             

            Thanks again