Game Development Reference
In-Depth Information
eilknpbh]od*`eolh]u*Ikrea?hel 7
eilknpbh]od*arajpo*IkqoaArajp 7
Imports the MouseEvent class. You
need to import one of AS3.0's event
classes before you can listen for
events in your program.
lq^he__h]oo I]ej atpaj`oIkrea?hel
lq^he_bqj_pekj I]ej$%
op]ca*]``ArajpHeopajan$IkqoaArajp*?HE?G (kj?he_g%7
bqj_pekj kj?he_g$ arajp6IkqoaArajp %6 rke`
pn]_a $ Ukq_he_ga`kjpdaop]ca %7
Registers an event that listens for
mouse clicks. The event listener is
attached to the stage. When the
mouse is clicked, the onClick
function definition is called.
The code inside this function
defintion runs when the stage is
clicked. The name of the function
defintion matches the second
parameter in the addEventListener
method call.
A function defintiion that
handles events is called
an “event handler.”
If you click on the stage, you'll see the
following in the Output window:
Figure 3-13. Add an event listener to the stage to “listen” for mouse clicks.
Importing an event class
To use an event listener, first import one of AS3.0's event classes. In this topic you'll be using the
IkqoaArajp and Gau^k]n`Arajp classes most frequently, although there are many others. The import
statement for the IkqoaArajp class looks like this:
Once it's imported, you can use it to find out what the mouse is doing, such as clicking things or mov-
ing around the stage.
Adding an event listener
The next step is to add an event listener, which detects when the mouse is clicked (you used this direc-
tive in the example program in Figure 3-13):
Event listeners are usually added to objects. In this example, you added it to the op]ca object using
dot notation.
Search Nedrilad ::

Custom Search