1 Reply Latest reply on Oct 27, 2011 11:49 AM by roestigraben

    Stop sound when same button is pressed

    dfaunce

      I'm a complete beginner to any type of programming, so I'm glad that I even got this small tiny script working without errors. I've been scouring the web for tutorials and help and I can't find any tutorial to help. But I know this is a Programming 101 fix, so if anyone

      wants to give me any advice, I'd gladly appreciate it.

       

      When I press Btn1 - a sound plays, BUT when i press another button (either Btn2 or Btn1 again) then the sounds overlap each other. Can someone help me

      Write an if statement such that when a second button is pressed that the first sound will STOP playing?  Here is what I have, I know my URLRequest could be simplified...but it works and thats all I care about right now.

       

      Thanks in advance!

       

      -David

       

      Untitled.png

        • 1. Re: Stop sound when same button is pressed
          roestigraben Level 1

          David,

           

          I am not an expert, but it looks like you just need to add a line ahead of the new request into each of your 2 functions

           

          channel = sound.stop();

          req = new URLRequest("/assets/song1.mp3");

                                                  sound = new Sound(req);

                                                  channel = sound.play();

           

           

          BR

          peter