Q&A key is Down in AS3

Q&A key is Down in AS3

Kevin Weidner writes
Hi Waarith,

I've watched a number of your videos and I'm curious about your use of code from senocular.com. For example, you use the keyObject.as class for it's keyboard functionality. I'm assuming AS3 has a "newer" way of handling the keyboard but you prefer the AS2 way and you don't comment about this in your tutorials. What is the reason? I'm new and just learning Flash from your tutorials so I don't know what AS3 uses.

Thank you,

This got me thinking, how can I make a key down event in as3. The reason I use Senocular's keyObject.as class is because it works. The reason we use classes in as3 is not to understand how the code works, but how to use it. Never the less I did some research on how to receive keyboard input. If I just use an event listener KeyboardEvent.KEY_DOWN I get lag in the response. I came up with this code.

This gets the keyCode which is a number that is sent to the variable keyIs. Than the Event.ENTER_FRAME listener looks to see if the left or right key is down and moves the hero movieclip accordingly.