11 Replies Latest reply on Oct 5, 2007 2:45 PM by kglad

    Can't get AS3 KeyboardEvent to work

    caseymanx
      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");

      }
      }

      }