5 Replies Latest reply on Oct 17, 2007 7:46 AM by clbeech

    Toggle Music on/off

    Jack.Straw
      Hello. I'm trying add a music on/off button to my flash project. The music is on it's own layer (called "sounds layer") and is an .mp3 set to repeat. What script command could I use to stop the music? I've tried...

      on (release)
      {
      stopAllSounds();
      }

      ... but that just halts the current sound loop, and the music just restarts. Any ideas?

      Thanks in advance,
      -Jack
        • 1. Re: Toggle Music on/off
          Level 7
          Use the Sound object, not the timeline...

          --
          Dave -
          Head Developer
          http://www.blurredistinction.com
          Adobe Community Expert
          http://www.adobe.com/communities/experts/


          • 2. Re: Toggle Music on/off
            Jack.Straw Level 1
            Sorry, i'm VERY new to flash and I'm trying to modify a script. I'm afraid I need a little more information. The "sounds layer" starts playing the music on frame 336 of the timeline. Selecting that frame/layer on the timeline shows me which sound file is being played and that it is set to repeat. However, I don't see a label for a "sound object" anywhere... nor a script that would start the music. I've been working under the assumption that the music is just part of the timeline. Is this incorrect?
            • 3. Re: Toggle Music on/off
              clbeech Level 3
              well it can be 'embedded' into the timeline, but it's not the idea way of playing sounds, particularly a music file, and it will eat up a lot of memory to store the sound file (like music) in the swf. Better to use a 'Sound Object' like Dave says above, you have more control of it, and can load the Sound in even 'stream' it from an external file.

              Hit F1, and goto the ActionScript class references and look up 'Sound'. Also you'll find that the Flash Help manual is a huge resource to get you going, and has an amazing amount of information on evenything to do with Flash.

              Are you using AS3?
              • 4. Re: Toggle Music on/off
                Jack.Straw Level 1
                Ahhh, ok.. that makes sense to me. Thanks! I'll delete that layer and learn how to add the sound back in a more functional manor.

                Thanks for your help!
                • 5. Re: Toggle Music on/off
                  clbeech Level 3
                  great, you're welcome :)

                  I just now realized your probably using AS2 since you'd been able to attach the code above to an Object instance. so let me give you a quick rundown on how you can do this.

                  you add a sound by loading it in from a file (let's assume that, and that the file is in the same folder as the swf file) then you can set you buttons to control that sound instance. later you can load a different sound into the same Object and use the same buttons to control it. So the code to do this will look something like this: