forked from: charCode vs. keyCode

by aobyrne forked from charCode vs. keyCode (diff: 9)
♥0 | Line 30 | Modified 2012-04-20 07:35:30 | MIT License
play

ActionScript3 source code

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

// forked from grapefrukt's charCode vs. keyCode
// 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.height = 100;
            tf.width = 100;
            tf.x = 10;
            tf.y = 10;
            tf.selectable = false;
            tf.border=true;
            tf.text = 'hw';
            addChild(tf);           
           
            
            stage.addEventListener(KeyboardEvent.KEY_DOWN, handleKeyDown);
           
        }
        
        public function handleKeyDown(e:KeyboardEvent):void{
               wtrace("charCode:\t" + String.fromCharCode(e.charCode) + "\nkeyCode:\t" + String.fromCharCode(e.keyCode));
        }
        
        public function wtrace(text:String):void{
            tf.appendText(text + "\n");
            tf.scrollV = tf.maxScrollV + 5;
        }
    }
}