Hola
Mikeggg !
Puedes hacerlo de la siguiente forma:
Código PHP:
import mx.events.EventDispatcher;
import mx.utils.Delegate;
class KeyBoardAdapter extends EventDispatcher {
public static var KEY_PRESS:String = "onKeyPress";
private var _listener:Object;
private static var _self:KeyBoardAdapter;
//Constructor privado, obtener instancia con el método estático getInstance
public function KeyBoardAdapter() {
_listener = new Object();
_listener.onKeyDown = Delegate.create(this, onKeyDown);
Key.addListener(_listener);
}
public static function getInstance():KeyBoardAdapter {
if(_self == null) {
_self = new KeyBoardAdapter();
}
return _self;
}
private function onKeyDown(evt:Object):Void {
var ascii:Number = Key.getAscii();
var letter:String = String.fromCharCode(ascii);
dispatchEvent({type:KEY_PRESS, target:this, code:ascii, letter:letter});
}
}
Y la forma de utilizarla:
Código PHP:
var key:KeyBoardAdapter = KeyBoardAdapter.getInstance();
key.addEventListener(KeyBoardAdapter.KEY_PRESS, onKeyPress);
function onKeyPress(evt:Object):Void {
trace(evt.letter);
trace(evt.ascii);
trace(evt.target);
}
Un saludote !