1 Reply Latest reply on Jan 26, 2012 4:31 AM by Ned Murphy

    Button to start and stop music?

    cheztheguy

      Hello,

      I'm fairly new at AC2 (Yes, I need to update), and I have Flash CS3.

      I need to find out if I can have a button that when you click it, plays a music file, and then when you click it again, the music that was playing for that button would stop.

      I have a text box on top of a rectangle and I selected them both and converted them to a button symbol, named it MusicFile, double clicked on the new button, inserted a new keyframe in the timeline on "down" (where it says Up, Over, Down, Hit), and then dragged the music file from the library onto the button. It works fine, until I click the button a second time, and it just keeps playing as if I pushed play twice and two copies of the sound started playing.

       

      Is it possible to make the button play the music when it's clicked the first time, then stop the music that it was just playing the second time it was clicked?

       

      Just wondering.

       

      Thanks!

        • 1. Re: Button to start and stop music?
          Ned Murphy Adobe Community Professional & MVP

          If you want to control the playing of sounds you do not want to be placing the sound in the timeline.  You should search Google for tutorials using terms like "AS2 Sound tutorial" to learn about using the Sound class.  Here's one result that I believe includes files you can download.

           

          http://www.kirupa.com/developer/actionscript/sound.htm

           

          One thing bad about this particular tutorial is that it places code on the button.  You should avoid that practice and place the code in the timeline.

           

          To have the same button do different tasks you will want to incorporate toggling logic such that when you click it the true/false state of a boolean variable changes, and ten use that boolean in a conditional to determine whether it's time to play versus time to stop.

          1 person found this helpful