Game Development Reference
Displaying the instance on the stage
You now have a shiny new instance of the Op]npL]ca symbol stored as a reference in the op]npL]ca
variable. This new instance exists as an object you can access with code. But it isn't visible on the stage
yet. You first need to tell the program to actually display it. That's exactly what this directive does:
]``?deh` is one of AS3.0's built-in methods. (The first built-in method you saw in Chapter 1 was pn]_a,
which displays information in the Output panel.) ]``?deh` is a deliciously cute little method that
(besides its many other talents) displays instances of Movie Clip symbols on the stage. Any information
inside the parentheses of a method is known as the method's argument . When you use the ]``?deh`
method, it assumes that you want to display the instance you provided in the parentheses on the
stage. (You can also use ]``?deh` to display instances inside other objects; you'll see examples of how
to do this in later chapters.)
What ]``?deh` has done in the program is take the op]npL]ca instance and add it to something called
the display list . Any instances that are on the display list are visible on the stage.
With the first three directives that you've written in the program, you created a storage box, filled the
box with an instance, and then tipped the box over to display its contents on the stage. Figure 3-7 takes
you on a tour of how these three directives have worked together to display the op]npL]ca instance.
lq^he__h]oo I]ej atpaj`oIkrea?hel
op]npL]ca9 jas Op]npL]ca7
The startPage variable is
decalared within the class
definition so that it can be used
in any of the class's methods.
These directives are in the constuctor
method because they need to run as
soon as the Main class is instantiated.
Because the Main class was set as
the FLA's document class, it will be
instantiated automatically when the
SWF runs. That means the startPage
instance is displayed immediately.
addChild adds the
instance to the display
list. Instances on the
display list are displayed
on the stage.
Figure 3-7. The process of displaying an instance on the stage