# Is this achieved with Listeners?

**URL:** <https://forum.kirupa.com/t/is-this-achieved-with-listeners/306673>\
**Category:** flash\
**Created:** [March 19, 2010, 5:57pm UTC](https://forum.kirupa.com/t/is-this-achieved-with-listeners/306673 "2010-03-19T17:57:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![capdetrons](https://avatars.discourse-cdn.com/v4/letter/c/df705f/32.png) [@capdetrons](https://forum.kirupa.com/u/capdetrons)\
**Post date:** [March 19, 2010, 5:57pm UTC](https://forum.kirupa.com/t/is-this-achieved-with-listeners/306673/1 "2010-03-19T17:57:00Z")

</div>

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);
