0 Replies Latest reply on Jun 17, 2007 10:43 PM by jpwrunyan

    Keyboard event listener not working in Actionscript!

    jpwrunyan Level 1
      Ok, this source is straight out of O'Reilly's Actionscript 3.0 Cookbook:

      package {

      import flash.display.Sprite;
      import flash.events.KeyboardEvent;

      public class Events extends Sprite {

      public function Events() {

      stage.focus = this;
      this.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);

      }//end constructor

      private function onKeyDown(event:KeyboardEvent):void {

      trace ("keydown: "+event.charCode);

      }//end private function

      }//end class

      }//end package

      The problem is that the trace doesn't run at all! I don't think the event is being caught at all! What the heck?
      If I add the listener to stage instead of "this" THEN I get a response. This is really frustrating!
      Can someone tell me if this is some kind of bug? Is O'Reilly wrong? What is happening?