Game Development Reference
In-Depth Information
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`$op]npL]ca%7
]``?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.
1.
r]nop]npL]ca6Op]npL]ca7
l]_g]ca
w
eilknpbh]od*`eolh]u*Ikrea?Hel 7
lq^he__h]oo I]ej atpaj`oIkrea?hel
w
r]n op]npL]ca6Op]npL]ca7
lq^he_bqj_pekj I]ej$%
w
op]npL]ca9 jas Op]npL]ca7
]``?deh` $op]npL]ca%7
y
y
y
op]npL]ca
Class
Definition
The startPage variable is
decalared within the class
definition so that it can be used
in any of the class's methods.
2.
op]npL]ca9jasOp]npL]ca$%7
Constructor
Method
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.
op]npL]ca
3.
]``?deh`$op]npL]ca%7
$%
addChild adds the
instance to the display
list. Instances on the
display list are displayed
on the stage.
op]npL]ca
Figure 3-7. The process of displaying an instance on the stage
 
Search Nedrilad ::




Custom Search