2 Replies Latest reply on Jul 9, 2010 3:27 AM by toastiesmonster

    Question on keyboard control, gettimer, play/pause, fast forward/rewind

    toastiesmonster

      I embedded keyboard control actionscript into my flash animation in order to pause the animation by pressing "Enter" and play it again with "SpaceBar". Here is the scripts I am using:


      //
      keyListener = new Object();
      var isStopped : Boolean = false;

      keyListener.onKeyDown = function() {
         var keyCode = Key.getCode();
        
         if (keyCode == 13) {
            _root.play();
              }
      if (keyCode == 32) {
            _root.stop();
              }
      };
      Key.addListener(keyListener);
      //

       

      Other than keyboard control, I also added four buttons to the animation so that user can click the dedicated button to play and pause, to fast forward and rewind.

      PLAY button:

      //

      on(release) {
      play();
      }
      //

       

      PAUSE button:

      //
      on(release) {
      stop();
      }
      //

       

      FAST FORWARD / REWIND button:
      //
      on(release) {
      gotoandplay("50");
      }
      //

       

      Other than above, I also added getTimer to delay certain frame in the animation.

       

      //
      stop();
      t = getTimer();
      onEnterFrame = function(){
          if(getTimer()>= t+11000){
              play();
              onEnterFrame = undefined;
          }
      }
      //

       

      Seems like the above code isn't compatible with each other and that sometimes the animation cannot be stopped by clicking the Pause button nor by pressing the dedicated key on the keyboard (e.g. ENTER/SPACEBAR)

       

      Can anybody advise if any of the above is crashed or not solid? Please help. Highly appreciated.