Unfortunately, Flash makes this a little bit tougher for you. Instead of giving each key a letter representation, the developers of Actionscript 2.0 gave each key a number representation.
For example, suppose you are developing a sice-scrolling adventure game, and want to have your character walk right when the 'd' key is pressed down. It seems like it would be simple, but this often trips new Flash developers up. You can't just type Key.a. That would be too easy. Instead, you would type in something like if(Key.isDown(65)){... your code here... }
Why Are Key Codes Used?
Programmers like us need a way to keep out the guys and girls who don't put in the effort to learn a language (Okay, not really, but that is a nice side effect).
In reality, key codes weren't developed to make your life harder. Each character on the keyboard is mapped to a different number due to the way computers 'see' a character. Computers see data in bits and bytes. One bit contains two possible combinations (1 or 0). A byte is made up of 8 of these bits. Thus, a byte contains 256 different combinations. A character uses 7 bits, or 128 possible combinations, to convey to the computer what symbol you want to show up on the screen when your program is run.
This may seem a bit confusing at first, but if you have developed programs in other languages besides Flash you will recognize the numbers from the commonly accepted character encoding scheme called ASCII. ASCII stands for American Standard Code for Information Interchange. Don't worry if you don't understand it yet. It is very widely used in the programming world, but the only thing we need to know for now is that Flash uses a number between 0 and 127 for its key codes.
What are the key codes for Flash?
Now that we understand a little bit about how they work, let's talk about what the key codes actually are. I could go on and on about which each number represents, but I'll let you check out the Flash key codes for yourself.
No comments:
Post a Comment