Game Development Reference
In-Depth Information
The first difference is the name. By convention, the names for event handlers always begin with the word
on . Programmers choose to give event handlers names like kj?he_g, kjIkra, or kjOkiaGej`KbArajp so
that they're easy to spot among the other function definitions. You're free to give the event handler any
name you like, but you'll make your life a little easier if you stick to this convention. I'll be doing so for
the rest of this topic.
The second difference is the function definition's parameter:
Event handlers have to declare a special event variable , which also has to be the same type as the
event that occurred, such as IkqoaArajp.
What is this event variable? It's actually an object that is automatically created by AS3.0 when the
event takes place. Here's how it works:
Imagine clicking the stage with the mouse. As soon that happens, a ?HE?G event is triggered. The
?HE?G event is sent by AS3.0 to something called the event dispatcher . (You don't need to know
much about the event dispatcher except that it's a bit like a little software robot hanging around
your program listening for things.) As soon as it hears an event that you've told it to listen for, it takes
out a notebook and scribbles down quite a bit of information about the event. For example, if you
click a button, it can tell you the name of the button you clicked and where on the stage the click
took place. All this information is packaged together into an event object, which is sent to the event
handler (the function definition you programmed to run when the event occurs). However, the event
handler has to create a variable as one of its parameters to contain the event object. Even though you
may not actually need to use this event object in the function definition, AS3.0 requires that you cre-
ate a variable as a parameter to contain it.
So what kind of information does this event object contain? You can find out by using pn]_a to dis-
play its contents in the Output panel. You can change the example function definition so that it looks
something like this:
Now if you save the file, test the project, and then click the stage, you'll see something like this in the
Output panel:
That's a lot of information! Some of it might actually be very useful, although certainly not for the
current needs. Later in the topic you'll look at how you can access this information and use it in your
Search Nedrilad ::

Custom Search