I’m new to AS3, and I’m going to make a simple game and I need to learn some things.
The most important thing I need to know is Key Detection.
I’ve read this post but I didn’t understand it at all. I also think there must be a simpler way to do that.
So, I would be pleased if someone could post a code to make something happen when a key is pressed, and explain it a bit.
Here’s an example document class. I made it very basic, hope you get get something from it. Attached the FLA+AS as well.
package {
import flash.display.Sprite;
public class baseClass extends Sprite {
import flash.events.KeyboardEvent;
public function baseClass():void {
this.stage.addEventListener(KeyboardEvent.KEY_DOWN, processKey); // Attach listener for Key_down event
};
private function processKey(e:KeyboardEvent):void { // Function is called when event fires
trace("Key Code is: "+e.keyCode); // Keyboard code
trace("Character Code is: "+e.charCode); // Character code
};
};
};