Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 115

Programming actionscript 3.0
Table of Contents

Advertisement

Code that is external to the StaticVars class and any of its subclasses can reference the
and
totalCount
MAX_NUM
code works:
trace(StaticVars.totalCount); // 0
trace(StaticVars.MAX_NUM); // 16
You cannot access static variables through an instance of the class, so the following code
returns errors:
var myStaticVars:StaticVars = new StaticVars();
trace(myStaticVars.totalCount); // error
trace(myStaticVars.MAX_NUM); // error
Variables that are declared with both the
the same time as you declare the constant, as the StaticVars class does for
cannot assign a value to
code will generate an error because it is not a valid way to initialize a static constant:
// !! Error to initialize static constant this way
class StaticVars2
{
public static const UNIQUESORT:uint;
function initializeStatic():void
{
UNIQUESORT = 16;
}
}
Instance variables
Instance variables include properties declared with the
the
keyword. Instance variables, which are attached to class instances rather than to an
static
entire class, are useful for storing values that are specific to an instance. For example, the Array
class has an instance property named
particular instance of the Array class holds.
Instance variables, whether declared as
can, however, achieve functionality that is similar to overriding variables by overriding getter
and setter methods. For more information, see
Methods
Methods are functions that are part of a class definition. Once an instance of the class is
created, a method is bound to that instance. Unlike a function declared outside a class, a
method cannot be used apart from the instance to which it is attached.
properties only through the class itself. For example, the following
static
inside the constructor or an instance method. The following
MAX_NUM
length
or
var
and
keywords must be initialized at
const
and
var
const
that stores the number of array elements that a
, cannot be overridden in a subclass. You
const
"Get and set accessor methods" on page
. You
MAX_NUM
keywords, but without
120.
Classes
115

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents