9 Replies Latest reply on Nov 30, 2010 12:40 AM by miaklang

    Flash key.isdown problem

    Gespinha Level 1

      Hi there

       

      I`ve got a simple problem with my codes

       

      I have a character, And in its movieclip I`ve got 3 frames (first has an idle pose, second a walking pose and third a running pose), each with a movieclip with an action in it.

       

      Well, what I wanted is that when I am walking with this character, and press the SHIFT key he runs.


      And I`ve got the following code

       

      if (Key.isDown(Key.LEFT)) {
              _x -= speed;
              this.gotoAndStop(2);
              _xscale = -scale;
          }
          if (Key.isDown(Key.RIGHT)) {
              _x += speed;
              this.gotoAndStop(2);
              _xscale = +scale;
          }
          if (Key.isDown(Key.SHIFT)) {
              this.gotoAndStop(3);
              speed = run;
          } else {
              speed = walk;
              this.gotoAndStop(2);
          }
      }

       

      But when I clicke the shift button, he shows the first frame static of the movie clip in frame 3 (running frame).

       

      Whats happening?

       

      thanks in advance

        • 1. Re: Flash key.isdown problem
          Ned Murphy Adobe Community Professional & MVP

          It's not clear to me what the problem is.  You're saying if you press the SHIFT key the movieclip goes to frame 3, which is what you said it should do.

          1 person found this helpful
          • 2. Re: Flash key.isdown problem
            Gespinha Level 1

            Yes, the movieclip goes do frame 3, but instead of playing the animation thats within that frame it apears static, like as if in the movie clip there was not an animation.

            • 3. Re: Flash key.isdown problem
              Ned Murphy Adobe Community Professional & MVP

              I don't see that you have any problerm related to the key-isDown if the code is doing what it is supposed to do. Does the movieclip in frame 3 have a stop() in it?  If not, there is no reason for it not to play. If so, you should remove it.

              1 person found this helpful
              • 4. Re: Flash key.isdown problem
                Gespinha Level 1

                Actually I forgot to mention that I wanted to go to frame 3 only if SIFT and one of the directional buttons were pressed.

                 

                Because he does apear moving, but only when none of the other keys are pressed at the same time.

                • 5. Re: Flash key.isdown problem
                  Ned Murphy Adobe Community Professional & MVP

                  Consider the following and if it agrees with what you have planned, just change the traces to the code you intend for each case...

                   

                  var keyListener:Object = new Object();
                  Key.addListener(keyListener);

                   

                  keyListener.onKeyDown = function(){
                      if (Key.isDown(Key.LEFT)) {
                         if (Key.isDown(Key.SHIFT)) {
                                    trace("run");
                         } else {
                                    trace("walk");
                         }
                     }

                   

                     if (Key.isDown(Key.RIGHT)) {
                         if (Key.isDown(Key.SHIFT)) {
                               trace("run");
                         } else {
                               trace("walk");
                         }
                     }
                  }

                   

                  Also, in the event you don't like that it stops when you have a keyUp event, change it all to...

                   

                  this.onEnterFrame = function(){
                        if (Key.isDown(Key.LEFT)) {
                              if (Key.isDown(Key.SHIFT)) {
                                    trace("run");
                              } else {
                                    trace("walk");
                              }
                        }

                        if (Key.isDown(Key.RIGHT)) {
                              if (Key.isDown(Key.SHIFT)) {
                                    trace("run");
                              } else {
                                    trace("walk");
                              }
                        }
                  }

                  • 6. Re: Flash key.isdown problem
                    Gespinha Level 1

                    Yes, the second one solved the trick

                     

                    Thanks.

                     

                    The shift at the same time is solved, but the movieclip within frame 3 doesn`t still work

                     

                    Is it possible to post here the problem? So you could see an example?

                    • 7. Re: Flash key.isdown problem
                      miaklang

                      Hi

                       

                      Just wondering if you managed to solve this problem regarding flash key.isdown problem. I have the exact same problem at the moment, just with 3 state, standing still, moving right and moving left, but the animations dont play inside each of these states when pressed, seems like it goes to frame one of the animation and just stays there because the button is being pressed.

                       

                      Thanks for any help

                      • 8. Re: Flash key.isdown problem
                        Gespinha Level 1

                        No, never got it solved.

                         

                        But anyway, I`ve started then studying some actionscript 3.0, and I tell you it`s a lot better.


                        I strongly suggest you change to it, as I read on the net that Adobe plans to remove AS2 capability from the next flash version, which means it will probably end by being "eaten" by AS3.

                        • 9. Re: Flash key.isdown problem
                          miaklang Level 1

                          That doesnt sound good at all, thanks for the info!