4 Replies Latest reply on Nov 23, 2010 1:10 PM by gaminflash

    Time event problem number 2

    gaminflash Level 1
      Hello again, i am having a problem with the time event. It works properly the first time but after like 2 times switching directions, it starts to change the second delay or something and here is the actual script:
      speed=3;
      moveableup=true
      moveableleft=true
      moveableright=true
      moveabledown=true
      var dir
      dir = 0;
      a.onEnterFrame=function(){

       


      if(Key.isDown(Key.UP) && moveableup == true ){
      moveableleft = false;
      moveabledown = false;
      moveableright = false;
      moveableup = false;
      dir = 1
      setTimeout(reset,1700);
      }
      if(Key.isDown(Key.DOWN) && moveabledown == true){
      moveableleft = false;
      moveableup = false;
      movableright = false;
      moveabledown = false;
      dir = 3
      setTimeout(reset,1700);
      }
      if(Key.isDown(Key.LEFT) && moveableleft == true){
      dir = 2
      moveableup = false;
      moveabledown = false;
      moveableright = false;
      moveableleft = false;
      setTimeout(reset,1700);
      }
      if(Key.isDown(Key.RIGHT) && moveableright == true){
      moveableup = false;
      moveabledown = false;
      moveableleft = false;
      movealberight = false;
      dir = 4
      setTimeout(reset,1700);
      }
      if(dir == 1){
      this.gotoAndStop("up");
      }
      if(dir == 2){
      this.gotoAndStop("left");
      }
      if(dir == 4){
      this.gotoAndStop("right");
      }
      if(dir == 3){
      this.gotoAndStop("down");
      }
      if(dir == 0){
      this.gotoAndPlay("stand");
      }
      }
      function reset(a:MovieClip){
      moveableleft=true;
      moveableup=true;
      moveabledown=true;
      moveableright=true;
      }

      how do i fix this script so it will wait 1.7 secs after each k:S?
        • 1. Re: Time event problem number 2
          Ned Murphy Adobe Community Professional & MVP

          It may just be your RIGHT code that is throwing things off since you have a misspelling in there...

           

          movealberight = false;

          • 2. Re: Time event problem number 2
            gaminflash Level 1

            I Misspelled there but that wasn't the issue, i kinda rewrote the whole script a couple of times and ended up with the same results or worse results... :/

            • 3. Re: Time event problem number 2
              Ned Murphy Adobe Community Professional & MVP

              If I revise your posted to just trace things and I fix that misspelling it works okay for me.  The timing between firings of the reset function is roughly 1.7 seconds as long as I hold one of the keys down.  This is the code I tested with, but don't replace what you have with it... just run it in a separate new file (with whatever object "a" is present).

               

              speed=3;
              moveableup=true
              moveableleft=true
              moveableright=true
              moveabledown=true
              var dir = 0;


              var dirArray = new Array();
              dirArray.push(0.0);


              a.onEnterFrame=function(){


              if(Key.isDown(Key.UP) && moveableup == true ){
              moveableleft = false;
              moveabledown = false;
              moveableright = false;
              moveableup = false;
              dir = 1
              setTimeout(reset,1700);
              }
              if(Key.isDown(Key.DOWN) && moveabledown == true){
              moveableleft = false;
              moveableup = false;
              movableright = false;
              moveabledown = false;
              dir = 3
              setTimeout(reset,1700);
              }
              if(Key.isDown(Key.LEFT) && moveableleft == true){
              dir = 2
              moveableup = false;
              moveabledown = false;
              moveableright = false;
              moveableleft = false;
              setTimeout(reset,1700);
              }
              if(Key.isDown(Key.RIGHT) && moveableright == true){
              moveableup = false;
              moveabledown = false;
              moveableleft = false;
              moveableright = false;
              dir = 4
              setTimeout(reset,1700);
              }

              }
              function reset(a:MovieClip){
              moveableleft=true;
              moveableup=true;
              moveabledown=true;
              moveableright=true;

               

              dirArray.push(getTimer());


              var deltaT = (dirArray[(dirArray.length-1)]-dirArray[(dirArray.length-2)])/1000;

               

              if(dir == 1){
              trace("up" + "   " + deltaT);
              }
              if(dir == 2){
              trace("left" + "   " + deltaT);
              }
              if(dir == 4){
              trace("right" + "   " + deltaT);
              }
              if(dir == 3){
              trace("down" + "   " + deltaT);
              }
              if(dir == 0){
              trace("stand" + "   " + deltaT);
              }
              }

              1 person found this helpful
              • 4. Re: Time event problem number 2
                gaminflash Level 1

                Yeah, i can see the trace now, it is as i thought, not 1.7 all the time. If you press buttons fast enough this will appear:

                 

                down   0.033
                right   0.633
                up   0.9
                right   0.198

                 

                Is there any script that actually can handle this or is this what happens if you press it too fast in flash?