0

I'm new to AS3. I tried to move a object with keyboard event. I used if/else condition to check that if keycode is this... then statement run.

But I'm not able to do it with switch method. I want to take a variable. what will store the keycode which key I'm pressing. & It will check for statement that I pressed 37 key, so object go to left.

So my problem is that, how to store current keycode (what key is pressing) to variable?

1

1 Answer 1

3
    stage.addEventListener(KeyboardEvent.KEY_DOWN, _keyboard);


    private function _keyboard(e:KeyboardEvent):void 
    {
        switch (e.keyCode) {
            case 38: // arrow up
                trace("It Works!");
            break;
        }
    }

Any problems with this?

As you can see your event stores information about keycode, and you can access it through it. Also note that listener is added to stage.

Sign up to request clarification or add additional context in comments.

1 Comment

oh. Thanks you so much for kindness. I was too close. But I didn't that I can use e.keycode to in switch. Its works great. Thanks again "Lukasz Zaroda"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.