Animate ActionScript 3.0 does not recognize key presses when testing, or published. Game.
Copy link to clipboard
Copied
I am going through a book tutorial on creating games in Flash/Animate, and the game is using keyboard key presses (arrow keys, spacebar) to control game elements. When I test the game, and also when I publish the game in .swf and windows exe format. The keys do nothing. This used to work years ago when I went through these examples previously, but now they aren't. I've looked through some troubleshooting sources, and I see a lot of references to something like "when testing the game, go to "Control/Disable Keyboard Shortcuts" because apparently, the testing environment is using keyboard shortcuts and has priority. However, in the current versions (2021, 2022) of Animate, I don't see anywhere where I can tell it to disable keyboard shortcuts for the test environment. Is there anyone that knows what to do about this now in the current software?
P.S., I'm not using Flash Builder, or any other ActionScript coding apps. It's all done in Animate.
Thanks.
Copy link to clipboard
Copied
are you assigning the listeners to "stage"?
Copy link to clipboard
Copied
Yes, I am.
Copy link to clipboard
Copied
it works for me.
create a new fla
add something to the stage.
add your keyboard listeners
test by clicking whatever is on stage and then press your keys
if that fails, show your code
Copy link to clipboard
Copied
SOLVED: I did a test, and further discovered that the key presses, do in fact work, but you have to mouseclick on the item first to give it the focus. Then the keystrokes will work. Even though the coding mentions the specific instance name or the Symbol.
However, I don't want to have to click something first. It's a game, I need the subject to just move. But I noticed that clicking anywhere on the stage made the arrows work.
I saw a post somewhere that talked about focus, so I established focus on the symbol with a simple "symbol.focus = symbol;"
That made the arrows work on the symbol without clicking anywhere, but it outlined my symbol with a yellow square. Weird.
So the final solution was just to put the focus on the stage with "stage.focus = stage;" and everything works as expected. SOLVED!
Copy link to clipboard
Copied
good

