The works below well, except in one scenario. When the username and/or password is wrong, the user is shown an alert box. If the user presses the Enter key to get rid of the alert box, the addListeners and trapKeys functions fire again. I understand why (the cursor is still in the TextInput field where the EventListener is listening), but am not sure how best to prevent it in this one scenario.
<mx:Script> <![CDATA{ private function handleLoginEvent() :void { remoteObject.login(username.text,password.text); loginButton.enabled=false; } private function addListeners() :void { stage.addEventListener (KeyboardEvent.KEY_DOWN, trapKeys); } private function trapKeys (e:KeyboardEvent) :void { if ((e.keyCode==13) ) { handleLoginEvent(); } } ]]> </mx:Script>