Skip to main content
Participant
February 8, 2014
Answered

Up (keyCode 38) and Down (keyCode 40) Keys Reversed?

  • February 8, 2014
  • 1 reply
  • 1579 views

Hi everybody,

I am using Adobe Flash CS4. I just took a tutorial for keyboard input, and when I test my movie, the up key causes downward motion and the down key causes upward motion.

Here is my code:

function onKeyPress(event:KeyboardEvent):void {

            if (event.keyCode==38) {

                trace("up arrow pressed");

                ball.y+=movement;

            }

            if (event.keyCode==40) {

                trace("down arrow pressed");

                ball.y-=movement;

            }

I am using a graphic called "ball" here.

Does anybody know why this is happening?

Thanks for reading

This topic has been closed for replies.
Correct answer Ned Murphy

y values increase as you move down the stage.  You want to reduce the y value to move up, and increase it to move down.

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
February 8, 2014

y values increase as you move down the stage.  You want to reduce the y value to move up, and increase it to move down.