2 Replies Latest reply on Jul 23, 2007 12:23 PM by webvalue

    Help needed to understand an example in livedoc

    webvalue Level 1
      Hi,

      Below is what I pasted from livedoc - an example of using events. However, since I am new to flex, I don't understand how I use this. How can I run this example? Thanks!

      package {
      import flash.display.Sprite;
      import flash.display.DisplayObject;
      import flash.events.*;

      public class KeyBoardEventExample extends Sprite {
      private var bgColor:uint = 0x00CCFF;
      private var size:uint = 80;

      public function KeyBoardEventExample() {
      var child:Sprite = new Sprite();
      child.graphics.beginFill(bgColor);
      child.graphics.drawRect(0, 0, size, size);
      child.graphics.endFill();
      addChild(child);
      stage.focus = child;
      child.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
      child.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
      }

      private function keyDownHandler(event:KeyboardEvent):void {
      trace("keyDownHandler: " + event.keyCode);
      trace("ctrlKey: " + event.ctrlKey);
      trace("keyLocation: " + event.keyLocation);
      trace("shiftKey: " + event.shiftKey);
      trace("altKey: " + event.altKey);
      }

      private function keyUpHandler(event:KeyboardEvent):void {
      trace("keyUpHandler: " + event.keyCode);
      }
      }
      }