Game Development Reference
In-Depth Information
So what kind of variable types are there? Here are all the data types that can be used by variables in
>kkha]j: Can take one of two values: pnqa or b]hoa; its default value is b]hoa.
Jqi^an: Any number, such as whole numbers (also known as integers ) and numbers that
include decimal places (also known as floating point numbers).
ejp: An integer, which is a whole number without a decimal place. It can be positive or nega-
tive. Because the CPU doesn't have to calculate any decimal places, using it speeds up the
program's performance. It's usually better to use the ejp type over the Jqi^an type if you
know you won't need to use decimals. The default value for the ejp type is ,.
qejp: Stands for unsigned integer . qejp is an integer that is only positive. This is an even
leaner version of the ejp type, so it's the fastest of them all. Use it whenever you can for the
best performance. qejp has a default value of ,.
Opnejc: Letters, words, or phrases—any text at all. You can even use the Opnejc type to store
numbers, but if you do, the numbers will be interpreted as text and you won't be able to
manipulate them mathematically. The default value for the Opnejc type is jqhh, which means
“no data of any kind.”
K^fa_p: A general type. The K^fa_p class in AS3.0 is the base class for all other objects. The
K^fa_p class also has a default value of jqhh.
rke`: A very specialized type that is used only for methods that don't return values. It's not
used for variables. It can contain only one value: qj`abeja`. The qj`abeja` value is very similar
to the jqhh value, except that it is used when the variable hasn't yet been assigned a data type,
or if it contains numbers or Boolean values. All the methods so far have been declared with
a data type of rke`.
& (asterisk): If you want to create a variable that has no specific type or you need it to be really
flexible to be able to contain different data types at different times, replace the type name
with an asterisk. For example, you might use a line of code like this:
This variable now can hold any type of data. One suggestion regarding the use of the asterisk is
this: don't use it! Unless you have an extremely good reason why you want your variables to be
able to contain more than one type of data, you're opening up your program to a potential can
of worms. Forcing variables to a particular type is one of the great strengths of AS3.0 because
it prevents bugs and errors that are the result of the wrong type of data being stored in the
wrong type of variable. These kinds of errors can often be very difficult to debug.
The ejp, qjep, and rke` data types start with a lowercase letter; the others all start
with uppercase letters.
You can file these data types away for later, but you'll be using all of them over the course of this
topic. From today's menu, you have two of them on the plate: op]npIaoo]ca is a Opnejc, and
iuopanuJqi^an is a qejp type. The first thing the ejep method does is to assign values to these variables:
Search Nedrilad ::

Custom Search