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
    http://stackoverflow.com/questions/2613196/check-keyboard-state-without-using-keyboardevent-in-as3/2624924#2624924 – ansiart Jun 19 '12 at 18:28

1 Answers1

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.

Łukasz Zaroda
  • 869
  • 2
  • 19
  • 55
  • 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" – Lokesh Yadav Jun 19 '12 at 12:42