Game Development Reference
In-Depth Information
The op]npL]ca variable has been created, but it's empty. Let's fill it with something!
I could have chosen any name for this variable, such as pdaRanuBenopL]ca or op]n)
pKbPdaOpknu, but just to keep things organized in my own mind, I chose to give it
exactly the same name as the symbol in the Library that I want it to refer to. One
important difference between the name of the variable and the name of the type is
the choice of capitalization used. The variable name is written in lowerCamelCase.
The type is written in UpperCamelCase. This is the same reasoning I followed when
I named the _]p instance on the stage as a lowerCamelCase version of its parent ?]p
symbol in the Library . It means that I can easily tell the difference between the class
and the instance just by looking at the capitalization. (This topic follows the naming
convention of using lowerCamelCase with variable names; class and symbol names
use UpperCamelCase.)
Creating an instance
Previous chapters looked at how instances differ from the parent symbols that they come from. The
_]p character on the stage is an instance of the ?]p symbol in the Library . The clouds in the storybook
sky are all instances of their parent ?hkq` symbol. It's very easy to see this relationship when you're
working with Flash's graphic design tools.
You can also create instances of symbols using AS3.0 programming code. Although it's not so easy to
see this visually, the result is exactly the same as dragging an instance of a symbol from the Library
onto the stage.
So far, the code has created an empty variable called op]npL]ca to store an instance. The next step
is to create an instance of the Op]npL]ca symbol and store it in that variable. That's what the next
directive does:
op]npL]ca9jasOp]npL]ca7
The job of the jas keyword is to make instances. In this directive, it's used to tell the program that
you're creating a new instance of the Op]npL]ca symbol. The equal sign is used to copy a reference of
that instance into the op]npL]ca variable.
In simpler terms, you took the empty op]npL]ca variable and put an instance of the Op]npL]ca symbol
into it. The empty container is now full and ready to be used. Figure 3-6 illustrates what happened.
Now you have an instance of the Op]npL]ca symbol that you can access with programming code. The
next step is to actually display the instance on the stage so you can see it.
 
Search Nedrilad ::




Custom Search