LivestockTony
07-29-2008, 11:54 PM
FlashDevelop/mxmlc AS3 only environment-
I've been working on my first flash game, which uses asdw and ijkl keys for movement... I had the gameplay working, and moved on to adding menus, etc... I still register the keyhandler to the stage on startup to allow checking the m keyup event to turn the music on/off
I have noticed, that when the user clicks on my SimpleButton for New Game, the keyboard loses focus until the user clicks on the flash window again. stage.hasEventListener(KeyboardEvent.Key_UP) traces as true in my render loop, but my keyhandler doesn't won't trace no matter what the user presses once in the game unless the user clicks on the screen.
(My keyhandler is basically a large switch-case statement, I put the trace before the switch in the function)
The function called by the new game button calls two functions, one unregisters the mouseEvents associated with the buttons on screen, then calls removeChild on all the menu screen objects. The second function calls my game_setup() function.
I've been into the Adobe docs, and I can't find it but am I right in thinking I'm losing focus because I've removed all of the objects on screen before adding the game objects? If so, what's the preferred way to avoid that? Is there a stage.whatever setting which forces keyboard focus?
Thanks,
-TF
I've been working on my first flash game, which uses asdw and ijkl keys for movement... I had the gameplay working, and moved on to adding menus, etc... I still register the keyhandler to the stage on startup to allow checking the m keyup event to turn the music on/off
I have noticed, that when the user clicks on my SimpleButton for New Game, the keyboard loses focus until the user clicks on the flash window again. stage.hasEventListener(KeyboardEvent.Key_UP) traces as true in my render loop, but my keyhandler doesn't won't trace no matter what the user presses once in the game unless the user clicks on the screen.
(My keyhandler is basically a large switch-case statement, I put the trace before the switch in the function)
The function called by the new game button calls two functions, one unregisters the mouseEvents associated with the buttons on screen, then calls removeChild on all the menu screen objects. The second function calls my game_setup() function.
I've been into the Adobe docs, and I can't find it but am I right in thinking I'm losing focus because I've removed all of the objects on screen before adding the game objects? If so, what's the preferred way to avoid that? Is there a stage.whatever setting which forces keyboard focus?
Thanks,
-TF