8 Replies Latest reply on Apr 28, 2010 9:24 AM by 66jonez

    Looping one 10 second sound file.. saaaave meeee!!

    66jonez

      Ok...  so I am a newbie to flash pretty much.  So forgive me in advance.  I

      am trying to loop a small sound file (wav file because I was told wav will loop seemlessly)...

      in any case, got the actionscript (2.0) to work with one simple button that acts as a

      start and pause...  but yet, the file still doesnt loop.

       

      Does anyone have an actionscript that accomplishes this that I can take a peek at?  I HAVE to be missing something small..  its driving me nuts.

      It just will not loop.

       

      Thanks a ton.

      Dann

        • 1. Re: Looping one 10 second sound file.. saaaave meeee!!
          Ned Murphy Adobe Community Professional & MVP

          Can you describe the details of steps you took to create this and include the code you are using?

          • 2. Re: Looping one 10 second sound file.. saaaave meeee!!
            66jonez Level 1

            Here's the code...

             

             

            var snd:Sound = new Sound();      //Create a new sound object
            var sndFile:String;
            var sndPlaying:Boolean = true;      //Status flag indicating whether the sound is playing or not
            var sndFinished:Boolean = false;     //Status flag indicating whether the sound has finished playing or not
            var startVolume:Number;        //Start value of sound volume
            var autoStart:Boolean;

            //Extract the sound file name from the calling object
            if (this.sndfile != undefined) {
            sndFile = this.sndfile;
            }
            else {
            //Default setting is "songnamehere".mp3
            sndFile = "pinknoise.mp3";
            }

            if(this.sndvol != undefined) {
            startVolume = int(this.sndvol);
            } else {
            startVolume = 50;
            }

            if (this.sndautostart == 0) {
            autoStart = true;
            } else {
            autoStart = false;
            }

            snd.loadSound(sndFile, true);     //Load the specified sound file and start streaming
            snd.setVolume(startVolume);       //Set initial sound volume

            if(autoStart != true) {
            snd.stop();
            sndPlaying = false;
            sndFinished = true;
            mcPlay._visible = true;
            mcPause._visible = false;
            } else {
            sndPlaying = true;
            sndFinished = false;
            mcPlay._visible = false;
            mcPause._visible = true;
            }

            stop();

            snd.onSoundComplete = function() {
            sndPlaying = false;
            sndFinished = true;
            mcPause._visible = false;
            mcPlay._visible = true;
            }

            mcPlay.onRelease = function() {
            if(sndPlaying != true) {
              mcPause._visible = true;
              mcPlay._visible = false;
              if(sndFinished == true) {
               //Start playing the sound from the beginning
               snd.start(0,999999999999999999999);
              } else {
               //Start playing the sound only if it was previously paused
               snd.start(0,999999999999999999999);
              }
              sndPlaying = true;
              sndFinished = false;
            }
            }

            mcPause.onRelease = function() {
            //Pause sound playing
            snd.stop();
            sndPlaying = false;
            mcPause._visible = false;
            mcPlay._visible = true;

            • 3. Re: Looping one 10 second sound file.. saaaave meeee!!
              Ned Murphy Adobe Community Professional & MVP

              If you are streaming the sound, you cannot specify looping for it... per the help documents...

               

              loops:Number [optional] - A parameter that lets you specify the number of times the sound should play consecutively. This parameter is not available if the sound is a streaming sound.

              • 4. Re: Looping one 10 second sound file.. saaaave meeee!!
                66jonez Level 1

                I do not want to stream this file...

                • 5. Re: Looping one 10 second sound file.. saaaave meeee!!
                  Ned Murphy Adobe Community Professional & MVP

                  Then you need another plan because you do stream it...

                   

                  snd.loadSound(sndFile, true);     //Load the specified sound file and start streaming

                   

                  Try changing that second parameter to false and see if it does what you hope.

                  • 6. Re: Looping one 10 second sound file.. saaaave meeee!!
                    66jonez Level 1

                    hrmm yes i see that.  LOL...  told ya i m a newbie...  though i see its not as simple as just changing it to FALSE instead of true...  hrmm..

                    I do not want this file to start when they load the page..  just when they use the controls...  so I am really trying to keep with the script..

                    • 7. Re: Looping one 10 second sound file.. saaaave meeee!!
                      Ned Murphy Adobe Community Professional & MVP

                      In addition to changing that to false, you should probably tame that 99999999999999999999.... loops value to something more realistic--start small and test for when it doesn't work anymore.  I'm don't think the function is geared to handle a number that size.

                      • 8. Re: Looping one 10 second sound file.. saaaave meeee!!
                        66jonez Level 1

                        WOW!  Yup.. the crazy 9s did it!  I was trying for an infinite loop...  thus the 9's,,,

                        i have it at 99999 and its loopin,....

                        nice work!