3 Replies Latest reply on Feb 1, 2011 7:31 AM by kglad

    Need Help Looping Audio with AS

    agreatheight

      I built a graphic in which audio fades out on a button click. I also need it to loop the audio but I can't figure out how to do it. I cobbled it together from some old code I had, probably found on the net, and I am not sure where to put the looping parameters. Eveything works just as I need it to, I just need the sound to loop. Can anyone help? Here's the code:

       


      //************** create the sound objects ****************


      this.createEmptyMovieClip("holder1", this.getNextHighestDepth());
      var mySound1:Sound = new Sound(holder1);
      mySound1.loadSound("yourmusicgoeshere.mp3", true);

       


      //******************** button actions ************************

       

      //needed variables:
      var onFaded:Function;
      var currentSound:Number = 1;
      var busy:Boolean = false;
      var counter:Number;
      //

       

      b2.onRelease = function() {
              fadeOut(mySound1);
              };
             
      b3.onRelease = function() {
              fadeOut(mySound1);
              };
             
      bStop.onRelease = function() {
          mySound1.stop();
          currentSound = 0;
      };


      //************* fade out function *****************


      function fadeOut(theSound:Sound) {
          counter = 100;
          busy = true;
          clearInterval(nInterval);
          nInterval = setInterval(adjustSoundDown, 10, theSound);
      }
      function adjustSoundDown(theSound:Sound) {
          if (counter <= 1) {
              clearInterval(nInterval);
              theSound.stop();
              busy = false;
              onFaded();
          } else {
              counter--;
              theSound.setVolume(counter);
          }
      }