Game Development Reference
In-Depth Information
What this directive does is use the naikraArajpHeopajan method to remove the event listener that
you added earlier. Yes, that's right, actually remove it. Why would you want to do that?
You want the frog to open its mouth when the mouse moves over it. But you want that to happen only
once—the first time. The easiest way to prevent it from happening again is to remove the listener that
called the kjBnkcIkqoaKran method as soon as the frog arrives at frame 2. Once a listener is removed,
it's gone for good and will never call the event handler again.
If you left the event listener running, it would move the frog back to frame 2 every time the mouse
moved over it. In a different context, that might have been just fine and dandy, but in this case it
would mean that the frog would jump back to frame 2 even after you've reached frame 3. It would
look a bit awkward. (If you like, you can see the effect of this by deleting the naikraArajpHeopajan
directive, saving the I]ej*]o file, and retesting the project.)
To remove an event listener, you use exactly the same syntax and arguments as you do to add one,
but use the naikraArajpHeopajan method name instead. You should always make a habit of remov-
ing event listeners after you no longer need them because if you don't, they'll still be running in the
background listening for events and using up precious memory and processing resources.
The kjBnkc?he_g event handler is almost identical to kjBnkcIkqoaKran, except for the specifics:
The directives tell the frog to move its timeline to frame 3 and then remove the event listener that was
listening for mouse clicks so that the reader can click the frog only once. Interestingly, by using the
?HE?G and IKQOA[KRAN events, you've effectively turned the frog movie clip into a button. And, there's
actually nothing stopping you from creating any of the buttons in your games like this if you want to.
Voila! The beginnings of a promising children's interactive storybook!
Using the timeline as a state machine
Using a timeline as a state machine is something that you'll find all kinds of uses for in your game proj-
ects. For example, you could have a door object that appears open on frame 1 and closed on frame
2. You could use it to store the different states of your player character in a platform game, such as
“walking,” “running,” “jumping,” and “falling.” You could create an object called `a_gKb?]n`o with
52 different symbols on 52 different frames, and then create a method that could shuffle the order of
the frames. You could even store all your game levels on different frames of one Movie Clip object,
and simply instruct it to advance by one frame each time the player reaches a new level.
Thanks to Flash's timeline, all this is very quick and easy to accomplish.
Search Nedrilad ::

Custom Search