Adding keyboard shortcuts to Flash
August 11th, 2007 . by polyGeekFlash animations are great. Unless you are testing and you have to watch the same animation, over and over. That gets real old real quick. But, with just a smattering of code and a few frame labels you can breeze through that animation and get to the point that you are testing on.
It’s very easy. You just create a Keyboard listener that looks at the key you pressed and then does something. In the example case you see here you can press the 1, 2, 3, or 4 key to skip to specific points in the animation. (Click on the animation first to give it focus.)
Or you can hit the forward-arrow key to gotoAndStop on the next keyframe if you want to look very closely at what your animation is doing. And of course the back-arrow key jumps back one frame.
To jump back to the beginning of the animation hit the backspace key. If you are doing this in the Flash IDE you need to publish and then select: Control -> Disable Keyboard Shortcuts, in order for the backspace and Enter keys to work.
Another nice benefit to this approach is that you can drag those keyframes with the frame labels around and the keyboard shortcuts will still jump to them without any changes to the code.
If you are using this for testing purposes you might want to remember to disable the keyboard listener before you go public. The easiest way to do that is to comment out the last line: // Key.addListener(skipListener);











