Hi,
I am working on a game and can’t get through the login screen. I’ve got this code in it, but I’d like to have the focus on the username_txt input.
How difficult is that?
I have a slight idea on components and textFields and am very confused right now.
Thanks to anyone replying this post,
this is my code. As you can see, the first lines are commented out because if I give the username input textfield like this, then the listener for the enter key won’t work. Right now I can tab to the input text field, but I’d like it to work straight away.
stop();
/username_txt.setFocus();
username_txt.onChanged = function():Void {
if (username_txt.length > 3 && username_txt.length <15) {
Key.addListener(keyListener);
}
};/
username_txt.tabIndex = 1;
password_txt.tabIndex = 2;
function login() {
var username:String = username_txt.text;
var password:String = password_txt.text;
if (username.length>2 && username.length<15) {
es.login(username, password);
gotoAndStop(“Waiting”);
}
}
login_btn.onRelease = function() {
if (username_txt.length > 2) {
login();
}
}
Key.removeListener(keyListener);
var keyListener:Object = new Object();
keyListener.onKeyDown = function(ev) {
if (Key.isDown(Key.ENTER)) {
login(username);
}
};
Key.addListener(keyListener);