5 Replies Latest reply on Oct 30, 2007 4:25 PM by kglad

    Stopping and Starting Music

    ScottE
      Hi All,

      I am trying to stop and then start a music loop when the user navigates to a certain movie clip. This is not associated with a button or object.

      I need some help on how to write the ActionScript so that when the user enters the mc the music stops. When they click to navigate to any other part of the site I need for the music to resume.

      I did try this but a mc that should play won't play (it's a flv that just freezes up) but the music does stop:

      mySound = new Sound(); //create sound object
      mySound.attachSound("soundFile"); //attach file to object

      this.onEnterFrame = function () {
      mySound.stop();
      }

      I am a newbie with ActionScript. I wanted to fade the music out and then back in but have given up on that.

      Please HELP!

      Many Thanks,
      Scott



        • 1. Re: Stopping and Starting Music
          kglad Adobe Community Professional & MVP
          onEnterFrame, despite its name, does not execute once upon entry of the playhead into a frame. it executes repeatedly whether the playhead is moving or not. so, that's not what you want to use.

          attached to the frame where you want your sound to stop, use:

          • 2. Re: Stopping and Starting Music
            ScottE Level 1
            Hi Kglad!

            Thank you sooooo much! That definitely works. Still not clear on the fade sound but I'll settle for this. Many thanks.

            Okay. Now when the user navigates to this mc the music stops (thanks to your help). Do you know how that when they exit this mc to navigate anywhere else in the site I can have the music resume? I'm hoping there is a command on exiting the movie clip the music will resume regardless of where they navigate to.

            Thank you again!

            Scott
            • 3. Re: Stopping and Starting Music
              kglad Adobe Community Professional & MVP
              there must be some way a user navigates away from this frame. commonly a button press would do it. it's in that button's code, that you would add

              • 4. Re: Stopping and Starting Music
                ScottE Level 1
                That works but then if the music is already playing when they click on the other buttons that has mySound.start() I get two instances of the sound file playing.

                Is there an If Then statement I can add that if the music is already playing not to start another instance of the sound file?

                Thanks!

                Scott
                • 5. Re: Stopping and Starting Music
                  kglad Adobe Community Professional & MVP
                  create a boolean variable that you use to record whether your sound's start() method has been most recently called or its stop() method.