charCode vs. keyCode

by grapefrukt forked from flash on 2011-10-8 (diff: 17)
♥0 | Line 29 | Modified 2012-04-19 15:50:01 | MIT License
play

ActionScript3 source code

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

// forked from grapefrukt's flash on 2011-10-8
package {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFormat;
    import flash.events.Event;
    import flash.events.KeyboardEvent;
     
    public class FlashTest extends Sprite {
        
        private var tf:TextField; 
        
        public function FlashTest() {
           stage.scaleMode = "none";
           
            
            tf = new TextField();
            tf.defaultTextFormat = new TextFormat("_sans");
            tf.height = stage.stageHeight;
            tf.width = stage.stageWidth;
            tf.x = 10;
            tf.y = 30;
            tf.selectable = false;
            addChild(tf);           
           
            
            stage.addEventListener(KeyboardEvent.KEY_DOWN, handleKeyDown);
           
        }
        
        public function handleKeyDown(e:KeyboardEvent):void{
               trace("charCode:\t" + String.fromCharCode(e.charCode) + "\nkeyCode:\t" + String.fromCharCode(e.keyCode));
        }
        
        public function trace(text:String):void{
            tf.appendText(text + "\n");
            tf.scrollV = tf.maxScrollV + 5;
        }
    }
}

Forked