1 Reply Latest reply on Jun 9, 2006 2:37 AM by Newsgroup_User

    Almost there

    Daninator
      Hiya, I finally found the code I needed for making a button that pauses sound, well... kind of. At the moment I press the play button once and the sound plays, then I can pause the sound with the pause button and resume it with the play button. The problem is when I press the play button when the sound's playing it plays the sound over the top of the sound that was originally playing and basically mucks everything up. Now, since this program will be used by kids they are most liable to keep pressing the play button just for the hell of it. Can someone please edit this code so that the play button knows when the sounds playing and will therefore not keep playing the sound over the top? I've tried to explain as best I can but tell me if you need more info.
      Here's the code:


      soundTest = new Sound();
      soundTest.attachSound("fish");
      soundTest.start();
      clipLength.text = soundTest.duration/1000+" s";
      pauseClip.onPress = function() { pausePositionS = soundTest.position/1000;
      soundTest.stop();
      };
      startClip.onPress = function() { if (soundTest.position == soundTest.duration) { soundTest.start(); } else { soundTest.start(pausePositionS); } }; //Feedback of Clip Position via Dynamic Text Boxes startClip.onEnterFrame = function() { currentPosition.text = soundTest.position/1000; };

      PS: All this code goes into a frame and startClip and pauseClip are my start and pause buttons.
        • 1. Re: Almost there
          Level 7
          // create a Boolean (true/false) variable to act as a flag
          // to tell if the sound is playing or not

          var isPlaying:Boolean;

          soundTest = new Sound();
          soundTest.attachSound("fish");
          soundTest.start();

          clipLength.text = soundTest.duration/1000+" s";

          pauseClip.onPress = function() {
          pausePositionS = soundTest.position/1000;
          soundTest.stop();
          // set the flag isPlaying to false
          isPlaying = false;
          };

          startClip.onPress = function() {
          // if the sound is not currently playing
          if (!isPlaying) {
          // start the sound at the appropriate point
          if (soundTest.position == soundTest.duration) {
          soundTest.start();
          } else {
          soundTest.start(pausePositionS);
          }
          // set the flag isPlaying to true
          isPlaying = true;
          }
          };

          Daninator wrote:
          > of it. Can someone please edit this code so that the play button knows when the
          > sounds playing and will therefore not keep playing the sound over the top?