I am trying to build a game and I can't get past the login frame when I try to have the username textfield focused and the enterkey as well if the username is not undefined, but I can't manage to get any results. This doesn't work, obviously
:upset: and if i use setDefaultPushButton, I can't have the focus on the input textField.

Does anyone have an idea of how it is done?


Selection.setFocus("username_txt");

var usernameListener:Object = new Object();
usernameListener.onChanged = function(){
if (username_txt.length > 3 && username_txt.length < 15) && (Selection.getFocus == username_txt){
Selection.getFocus(KeyListener);
}
}

username_txt.addEventListener(usernameListener);

var keyListener:Object = new Object();
keyListener.onKeyDown = function(ev) {
if (Key.isDown(Key.ENTER)) {
login(username);
}
};

Key.addListener(keyListener);