Game Development Reference
In-Depth Information
Recall from Chapter 1 that whatever code is in a class's constructor method will run
immediately as soon as the class is instantiated. The I]ej class was assigned as the
FLA's document class, so this happens as soon the SWF file runs.
Programming buttons
The next step in the interactive storybook project is to program the buttons so that you can see the
other pages in the storybook. But before I go into the specifics of how to do this, you need to take
a few steps back and look at some of the underlying principles behind the code you're going to write.
It's not difficult, but there will be a lot of new concepts to absorb quite quickly. You need to break
them down into manageable chunks and look at them one at a time.
So grab a cup of masala chai and make yourself comfortable on the sofa. You'll take a short break
from programming to have a detailed look at the following topics:
Dot notation
Methods
Event listeners
These three elements will be working together in the new code you're going to write.
Using dot notation
You have two buttons in the storybook so far: dehh>qppkj and lkj`>qppkj. You may recall that you
gave them these names in the Instance name field of the Properties panel after you dragged instances
of them into the Op]npL]ca symbol from the Library . (Refer to Figure 2-60 if you need a reminder.)
These buttons still exist with those names; the only difference is that now they're contained within the
op]npL]ca instance that you created in the program.
You can refer to the buttons inside the op]npL]ca instance
using these names:
op]npL]ca*dehh>qppkj
op]npL]ca*lkj`>qppkj
The dot is used to show that these button objects live inside
the op]npL]ca instance. This method of naming objects and
their properties hierarchically using dots is called dot nota-
tion . Figure 3-8 illustrates this.
The concepts behind dot notation are crucial to understand-
ing how to program with AS3.0. Let's quickly have a look at
a very simple example.
Figure 3-8. The button instances are contained
within the parent instance.
 
Search Nedrilad ::




Custom Search