Chapter 21 Example 10

by actionscriptbible
♥0 | Line 18 | Modified 2009-08-27 15:04:39 | MIT License
play

ActionScript3 source code

/**
 * Copyright actionscriptbible ( http://wonderfl.net/user/actionscriptbible )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/jrxJ
 */

package {
  import com.actionscriptbible.Example;
  import flash.events.KeyboardEvent;
  public class ch21ex10 extends Example {
    public function ch21ex10() {
      stage.addEventListener(KeyboardEvent.KEY_DOWN, onKey);
      stage.addEventListener(KeyboardEvent.KEY_UP, onKey);
      trace("event\t\tkeyCode\tcharCode");
      trace("-------------------------------");
    }
    protected function onKey(event:KeyboardEvent):void {
      var char:String = (event.charCode > 31)? String.fromCharCode(event.charCode) : "n/a";
      trace(event.type + "\t\t" + 
            event.keyCode + "\t\t" +
            event.charCode + "\t(" + char + ")");
    }
  }
}