Game Development Reference
In-Depth Information
The key codes that AS3.0 uses are based on ASCII, which is a fixed standard for inter-
preting numbers as characters. For example, the ASCII number 65 refers to the upper-
case letter A. However, different operating systems don't map these codes to the
keyboard keys in exactly the same ways. If you design and test a game using key codes
on a Windows computer and then run the SWF on another operating system such as
OS X, the key codes that you used might not match OS X's keyboard mapping. For this
reason, it's preferable to use the Gau^k]n` class's built-in key properties (such as HABP
and NECDP ) instead of the actual key code numbers.
If you need to use a key that isn't represented by these properties, you have to use a key
code number. Make sure that you test these key codes carefully on each operating sys-
tem your game will run on to ensure that it's mapped to the correct keys on every one.
Some keys that you might use for your game won't work while you're building and
testing the game in the Flash development environment. Flash reserves some keys for
shortcuts (for example, Crtl and S to save a file). So if you used any of these keys or key
combinations in your game, you need to hold down Shift while testing the keys to over-
ride Flash's own use of them. The keys will work fine in the published SWF.
Very simply, this is an eb+ahoa statement that figures out which key is being pressed and then moves
the lh]uan object left, right, down, or up by adding or subtracting 10 pixels from its t or u positions.
But there are a few new things here that might seem confusing at first glance, so I'll try to clarify this
a bit.
Event listeners send a lot of information to the event handler in a special arajp variable. All event
handlers have to include an event variable to store this information—it's just part of the deal. Event
variables that contain keyboard information are typed as Gau^k]n`Arajp variables, like this:
They're declared directly in the event handler, as this code in bold highlights:
lner]pabqj_pekjkjGau@ksj$ arajp6Gau^k]n`Arajp %6rke`w
You can access this arajp variable at any time to use the information it contains. One piece of infor-
mation is the key code number for the key that's being pressed. This number is stored in a property
of the arajp variable called gau?k`a. You can access it like this:
Search Nedrilad ::

Custom Search