I just came across this strange problem while writing a demo for car racing game on AS3. I don’t know how to start but please bear with me.
I have a button movieclip on a stage. It’s a “Play Game” button. When I click this button my game starts. So I press the button and game starts (also button is removed from the stage). Now I should be playing the game. But I could not play it. Why? Because my key press events are not getting fired, so I can’t drive my car. I had added the key listeners to stage but my events don’t respond. Then I mouse clicked on stage then viola my key press events are getting fired and suddenly I am able to drive my car. I scratch my head. Question marks appear over my head. I didn’t have the clue why this was happening? Here is the part flow of game code:

buttonClicked(){
    initGame();
    startGame();
}
initGame(){
    //init codes
    //adding keylisteners to stage
    //...........................................
}

So that is the flow. So when i enter startGame then somehow i am losing the focus on my stage since i am not able to get any response from any key events. But when i click on game screen/stage then my key events are working.
I didn’t found the valid reason behind it. I tried many things but couldn’t solve it. I googled it and found a simple solution on some forum. Solution is:

startGame(){
     stage.focus=stage;
     //.................................................start game codes.................
}

“stage.focus=stage” was the solution i found but i still haven’t figured out the reason behind this stupid problem. What i could conclude is that my focus is still with the button that i had pressed and focus hasn’t bubble up back to stage. So anyone who knows the reason, please do explain it.

Gracias