Game Development Reference
In-Depth Information
This directive creates an instance of the StartPage symbol and stores a reference to it
in the startPage variable
The equal sign copies a
reference to the instance
into the startPage variable
The “new” operator
makes an instance of
the StartPage symbol
Figure 3-6. Use the new keyword to create an instance of a class or symbol and store it in a variable.
Before you go much further, you should take a closer look at exactly what the purpose
of that equal sign is. In AS3.0, an equal sign is known as an assignment operator
because it is used to assign a value from whatever is to the right of it to a variable on
its left. This is very different from how an equal sign is used in mathematics, and this
difference often trips up novice programmers. In math, an equal sign means “is equal
to.” In programming, an equal sign means “gets the value of.”
Here's a really simple example. Let's say you have a variable that you want to use in
a game to keep track of the player's score. Let's call it lh]uanoO_kna. Suppose that
one player in the game gets a score of 12 points, and you want the game to remember
this number so you can figure out how well the player is doing. You can use the equal
sign to copy the number 12 into the lh]uanoO_kna variable, the same way you would
write an important number into a notebook for future reference. The code might look
something like this:
AS3.0 literally interprets this as follows: “The lh]uanoO_kna variable gets the value of
12.” Now whenever the AS3.0 program sees the lh]uanoO_kna variable, a little light
goes on and it thinks, “Aha! That means 12!”
Search Nedrilad ::

Custom Search