the way I deal with this is to use a switch statement on the currentState:

in init() I call registerGlobalKeyHandler()

which is


private function registerGlobalKeyHandler(): void{

     stage.addEventListener(KeyboardEvent.KEY_DOWN, keyHandler);
  }

and has this event handler:

private function keyHandler(event:KeyboardEvent):void{

      //handle the Enter key
      if (event.keyCode == 13){

switch (currentState){
case 'login':
if ( loginButton.enabled == true ){
tryLogin();
}
break;
case 'register':
if (registerButton.enabled == true){
tryRegister();
}
break;
...
      }
   }
}

This gives me a lot of control over what function responds in each part of
the application, and lets me govern a variety of keys in different ways
depending on what page we're on.

You could dispense with the switch statement and have the key click work the
same everywhere.



-- 
Andrew Wetmore
User Experience Director
Open Learning Exchange - www.ole.org
978-319-7324

Reply via email to