Game Development Reference
6. Save the I]ej*]o file.
7. Test the project. You can now click the buttons and view the pond and hill pages. You haven't
added buttons back to the start page yet, so you have to quit the SWF and run it again to get
back to the start.
The folder Opknu^kkgsepd^qppkjo in the chapter's source files contains the files for the project so far.
This very simple little program is a great example of how variables, dot notation, methods, and event
listeners all work together.
Looking at the onHillButtonClick event handler
I've discussed the mechanics of much of these elements in quite a bit of detail, but it's worth taking
a closer look at the event handlers that actually do the work of changing the storybook's pages. Here's
what the kjDehh>qppkj?he_g event handler looks like:
This event handler contains two directives: it displays the dehhL]ca instance and then hides the op]npL]ca
You've seen ]``?deh`$% before. ]``?deh`$dehhL]ca% simply displays the dehhL]ca instance on the
stage as simple as that. But when ]``?deh` adds instances to the display list, it adds them on top of
other instances. That means that the op]npL]ca instance is still actually on the stage; it's just being
covered up by the dehhL]ca instance, which is completely blocking it from view.
You could leave the op]npL]ca instance there. I mean, it's doing no harm and you can't see it anyway.
But it's generally not a good idea to leave things on the stage if they're not needed because the Flash
Player still devotes some fraction of its precious resources to maintaining it in memory. Remember
that performance is everything to a game designer. If you're not using something, don't blink; just get
rid of it.
The evil twin sister of ]``?deh`$% is a method called naikra?deh`$%. Its job is to remove instances
from the stage so that they're no longer visible. This removes the op]npL]ca instance from the stage: