views:

892

answers:

3

I am learning how to use Flash using CS4, and focusing mainly on ActionScript3 (since I come from a coding background and not a designer background).

I want to respond to the user pressing keys on the keyboard.

I have used the official example source at the Flash reference site and followed the CS4 instructions for classes. However, all it responds to is special keys like ctrl and shift, for these keys it works fine. For keys like a,b,c there is no response whatsoever. Am I doing something wrong? Is there some setting I need to change? Maybe I need to change something outside my ActionScript (like a project setting maybe). Any help would be greatly appreciated.

+1  A: 

Are you running it in full screen mode? You can't hear those keys if you are. (Security restriction)

Tyler Egeto
No, just doing the regular ctrl+enter in CS4 (Test movie)
Ko9
Odd, can you post the code?
Tyler Egeto
The code is in the link I mentioned in my question. I encountered it in my own code, but when testing with this official example I had the same problem...
Ko9
+2  A: 

A quite usual problem is that the Flash IDE shortcut keys won't respond (as they are used by the IDE). Make sure you also test your movie in a browser or in the standalone player.

Theo.T
Ah I do believe that is correct!
Tyler Egeto
I'm using trace() for my output, how can I see this output using the standalone player?
Ko9
I don't think you can, two options would be to setup a text field and change it's value, or look into using Flash Develop or another IDE.
Tyler Egeto
The easiest way I can think of to trace in the browser is to call a Javascript function from Flash that will do a Console.log in firefox with firebug installed.
Luke
Yes, that did it :-)I tested it in the standalone player and it works there.. Thanks for that.Do you happen to know if there's a way to not send keyboard output to the IDE? I'm currently using a Label to view my output.. but it's a lot more convenient if I can use my movie fully inside my IDE, using trace() and ctrl+enter to run it..
Ko9
Oops, found this myself. For those wondering the same thing:When you run "Test Movie" (ctrl+enter), a new window will pop up running the Movie.In this window, go to the Control menu and check the option: Disable Keyboard Shortcuts.This will stop forwarding the keys, and it will also remember it for future startups of this file.This means I can still test my movies as normal :-)
Ko9
A: 

The up and down handlers trap different kinds of keys:

KeyboardEvent.KEY_DOWN gets keyslike backspace and delete, while KeyboardEvent.KEY_UP gets the usual a-z suspects.