2 Replies Latest reply on Nov 10, 2010 9:24 PM by 5altAndVinegar

    Sound to play one at a time


      How do I make a command saying:


      if sound is playing - dont play sound, else, play sound?


      so that the sound effect only plays one at a time. So if holding down SPACEBAR for example, the sound will play and only after the sound finishes, can it loop if SPACEBAR is still pressed.


      Thanks in advance.

        • 1. Re: Sound to play one at a time
          Ned Murphy Adobe Community Professional & MVP

          Can you show the code you are currently using and describe how you incorporate the sound into the design?


          In a general sense, you can create your own variable that indicates the sound is playing which is set to true when the sound is commanded to play and is set to false either when the sound is complete or when the sound is commanded to stop.  You can use this variable in a conditional to keep from starting a new sound playing.

          • 2. Re: Sound to play one at a time
            5altAndVinegar Level 1

            Ok, I'll just copy and paste the relevent parts: (This is for a car-racing game)



                 HAND = Key.isDown(Key.SPACE)


                 if (HAND) {
                    speed  *= handbrake
                    var screechSnd:Sound = new Sound();
                    // SKIDDIES
                    if (speed > MAXskiddisplay) {
                    steer = steer_handbrake;
                    if (!skidding) setLastpos();
                    traction = handbrake_traction/surface; }
                else {
                    traction = Math.max(traction_max, Math.abs((speed-MAXturnSpd)/surface))
                    steer = steer_normal }




            So basically, when the handbrake (spacebar) is pressed, the handbrake effect will be applied to the car and it will skid (which works), but the problem is I also want a sound to play when it spacebar is pressed.


            The sound does play, however, when pressed, the sound plays many times over at the same time, rather than letting the sound finish for the sound to repeat itself again (if spacebar is still pressed - that is).


            Thanks again in advance