6 Replies Latest reply on Mar 16, 2009 8:44 AM by kglad

    Sound buttons

    smikerboyz Level 1
      Hi! I am making my website using scenes. On my first scene, I typed in an action with the following code:
      myMusic = new Sound();
      myMusic.loadSound("Growing Young.mp3",true);

      But then I want to make a button when you press it, it will stop the sound. Then it will turn to another button to play sound again. So how can I do this?
        • 1. Sound buttons
          Webshark2000 Level 1
          To stop the sound from playing use:


          What I would do is put this code on the first frame of your scene:

          myMusic = new Sound();
          myMusic.attachSound("Growing Young.mp3");

          You could have the button be a movieclip that has two frames to it. The first could indicate to press the button to stop the sound, and put:


          on the frame. Then put:


          on the button (movieclip) itself so that it goes to the second frame when it's clicked, which has the stopAllSounds(); command on it. Then they could click it again and it would go back to the first frame again and just start playing the music again.

          Someone else may have a better or more simple solution, but that should work.

          • 2. Re: Sound buttons
            smikerboyz Level 1
            Thanks! I'll try it out and see if it will work
            • 3. Sound buttons
              smikerboyz Level 1
              I have a slight problem. Your method works, I tried it out. However, I am using scenes, so I copied and pasted my buttons to each scene. When I pressed stop music in one of my scenes, and when I navigate away from that scene, the movie clip is back to frame 1 again that has the stopAllSounds();. But I don't want that to happen, I want the movie clip to stay at the same frame when there is no sounds. Is there such actionscript as "if there is sound then go to frame 2, if there is sound then go to frame 1" So any way into this?
              • 4. Re: Sound buttons
                kglad Adobe Community Professional & MVP
                to create a movieclip button that toggles your sound off and on, use:

                } else{
                • 5. Re: Sound buttons
                  smikerboyz Level 1
                  I think I got my movie clip sorted out but is there an actionscript that is something like if there is sound go to frame 1, if there is no sound go to frame 2?
                  • 6. Re: Sound buttons
                    kglad Adobe Community Professional & MVP