3 Replies Latest reply on Nov 27, 2009 6:10 AM by Ned Murphy

    Key listener not function properly....

    kiranYS

      hi...

       

       

      i have developed some code to play my flash animation.... left arrow and right arrow key are used to control my animation to go prevFrame and nextFrame.

       

      In exporting file it works fine, but if I press and hold some time like just 10ses then problem comes, the prevFrame and nextFrame not functioned properly. if I press key once it jumps 3 to 4 key frames at a time....

       

      how can i rectify this problem.........??????

        • 1. Re: Key listener not function properly....
          Ned Murphy Adobe Community Professional & MVP

          It sounds like you might be using an onKeyDown event to trigger your actions. You should try using onKeyUp instead.

           

          If that doesn't apply or doesn't help. you'll need to show the code you're using.

          1 person found this helpful
          • 2. Re: Key listener not function properly....
            kiranYS Level 1

            Thank you...

             

            but the probelm is still unsolved.........

             

            first i had used this code..........

             

             

            var keyListener:Object = new Object();

            keyListener.onKeyDown = function()
            {
            if (Key.isDown(Key.RIGHT))
            {
              trace ("You pressed Right key");
              nextFrame();
            }
            if (Key.isDown(Key.LEFT))
            {
              trace ("You pressed Left key");
              prevFrame();
            }
            };
            Key.addListener(keyListener);

             

             

            after your advice i changed my code as.................

             

             

            var keyListener:Object = new Object();

            keyListener.onKeyUp = function()
            {
            switch (Key.getCode())
            {
              case Key.LEFT :
               prevFrame();
               break;
              
              case Key.RIGHT :
               nextFrame();
               break;
              
              default :
               trace ("Not entered in any case");
               break;
            }
            };
            Key.addListener(keyListener);

             

             

            but still problem is same...........

            • 3. Re: Key listener not function properly....
              Ned Murphy Adobe Community Professional & MVP

              The reason it seems to skip is because each time you get back to the frame where you assign the listener, you are creating a new listener.  You need to either not involve that frame in your timeline travel or move the assignment of that listener to an object that will not switch frames.

              1 person found this helpful