Answered
Can't get AS3 KeyboardEvent to work
When I use the code below to capture a KeyBoard event I get
the following error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Racer$iinit()
at MyMain$iinit()
Can anyone tell me why?
-----Code------
package {
import flash.ui.Keyboard;
import flash.display.*;
import flash.events.*;
import RaceCar;
public class Racer extends Sprite {
//
public function Racer():void {
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownListener);
}
private function keyDownListener(e:KeyboardEvent):void {
trace("keyDownHandler");
}
}
}
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Racer$iinit()
at MyMain$iinit()
Can anyone tell me why?
-----Code------
package {
import flash.ui.Keyboard;
import flash.display.*;
import flash.events.*;
import RaceCar;
public class Racer extends Sprite {
//
public function Racer():void {
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownListener);
}
private function keyDownListener(e:KeyboardEvent):void {
trace("keyDownHandler");
}
}
}