Search code examples
actionscript-3flashactionscript

how to exit KeyboadEvent after transition to another frame


i'm bulding a flash desktop application where i have a frame (called "Frame1") that contains the following code:

stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
function keyDownHandler(event:KeyboardEvent){
       gotoAndPlay("Frame2");
    }

the transition from "Frame1" to "Frame2" happens when the user hits any keyboard button, when the user arrive to "Frame2" he needs to type his name in a text field, but when i type anything in the text field i immediately go back to "Frame1". So, is there a way to exit the KeyboardEvent when i'm at "Frame2" so that the user can use the keyboard to type without firing the KeyboardEvent in "Frame1".


Solution

  • You have to remove your listener after it goes to the Frame2:

    stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
    function keyDownHandler(event:KeyboardEvent){
           gotoAndPlay("Frame2");
           stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
        }