5 Replies Latest reply on Jan 24, 2010 7:17 AM by kglad

    Sound Control Question

    d0brin Level 1

      I have a question. I have a sound and its imported via AS. My question is how to make it when i stop it to go smooth not directly to stop the sound. For stopping it i use this code.

       

      mysound.stop();

       

      and my other question is when i use this:

       

      mysound.setVolume(30);

       

      how to make it not to change the volume of the other sound files (which are not imported with as but are in the timeline)?

        • 1. Re: Sound Control Question
          kglad Adobe Community Professional & MVP

          you need to use a loop (setInterval or onEnterFrame) to fade volume and then stop your sound (when the volume is 0).

           

          you can have, at most, one sound per movieclip timeline that you can control with actionscript.  so, create a unique movieclip for each sound:

           

          var mc1:MovieClip=this.createEmptyMovieClip("mc1",1);

          var s1:Sound=new Sound(mc1);

           

          var mc2:MovieClip=this.createEmptyMovieClip("mc2",2);

          var s2:Sound=new Sound(mc2);

          • 2. Re: Sound Control Question
            d0brin Level 1

            how to do that:

             

            you need to use a loop (setInterval or onEnterFrame) to fade volume and then stop your sound (when the volume is 0).

             

            can you help me with some AS code pls

            • 3. Re: Sound Control Question
              kglad Adobe Community Professional & MVP

              if you call fadeAndStop() while passing your sound and its target movieclip, it will fade and stop your sound.  the code below need only appear once in your application and can be used to handle any sound.

               

              var fadeSoundI:Number;

               

              function fadeAndStop(s:Sound,mc:MovieClip){

              clearInterval(mc.fadeSoundI);

              mc.fadeSoundI = setInterval(fadeSoundF,60,s,mc);

              }

               

              function fadeSoundF(s:Sound,mc:MovieClip){

              s.setVolume(s.getVolume()-3);

              if(s.getVolume()<=0){

              clearInterval(mc.fadeSoundI);

              s.stop();

              }

              }

              1 person found this helpful
              • 4. Re: Sound Control Question
                d0brin Level 1

                aha but the thing is that i attach and start the sound on the main timeline and my control btn (the button that controls the sound) is located at this location:  p.c whare p and c are movie clips, so how to link this button to control sound initiated on the main scene? Where to put the codes for fading...

                • 5. Re: Sound Control Question
                  kglad Adobe Community Professional & MVP

                  just like you normally would:  use the correct path to the timeline that contains your sound and the correct path to the timeline that contains those functions.