Game Development Reference
In-Depth Information
Many of these events don't work with the op]ca object that you used in the example, but they all work
with button and Movie Clip objects. Here are some examples of how you might register these events
using ]``ArajpHeopajan:
Figure 3-14 illustrates the basic model for creating an event listener and what happens when the event
Optional name of the
object you want to
attach the event to.
Method call to AS3.0's
built-in addEventListener
The name of the event you want to
listen for. Follow this format:
event class, dot, event name.
The function definition that contains
the directives that you want to run
when the event takes place.
The event is registered with AS3.0's “event dispatcher.”
It begins the job of “listening” for events.
If the event occurs, the event dispatcher does two things:
2. It creates an event object and sends
it to the function. The function stores
the object as a variable that is declared
as one of its parameters. The event
object can be used in the function to find
out more information about the event.
1. It calls the function
that was registered
with the listener.
Function definitions that handle events are known as event handlers.
By convention, the names of event handlers start with the word on.
Figure 3-14. How event listeners work
As you did with methods, you'll need a bit of practice and a few more practical examples before you
fully grasp how event listeners work. You'll see lots of examples of event listeners in action over the
course of this topic, so you'll have lots of opportunities to experiment with them and see their effects
in different contexts. The nice thing about event listeners is that they all use exactly this same format.
You don't have to absolutely understand every detail about how they work yet; you just need to know
how to use them to get the results you want for your game.
Search Nedrilad ::

Custom Search