Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 119

Programming actionscript 3.0
Table of Contents

Advertisement

Within the body of an instance method, both static and instance variables are in scope, which
means that variables defined in the same class can be referenced using a simple identifier. For
example, the following class, CustomArray, extends the Array class. The CustomArray class
defines a static variable named
an instance variable named
created, and an instance method named
variables.
public class CustomArray extends Array
{
public static var arrayCountTotal:int = 0;
public var arrayNumber:int;
public function CustomArray()
{
arrayNumber = ++arrayCountTotal;
}
public function getArrayPosition():String
{
return ("Array " + arrayNumber + " of " + arrayCountTotal);
}
}
Although code external to the class must refer to the
through the class object using
body of the
getPosition()
variable. This is true even for static variables in superclasses. Though static properties are not
inherited in ActionScript 3.0, static properties in superclasses are in scope. For example, the
Array class has a few static variables, one of which is a constant named
that resides in an Array subclass can refer to the static constant
identifier.
public class CustomArray extends Array
{
public function testStatic():void
{
trace(DESCENDING); // output: 2
}
}
The value of the
this
instance to which the method is attached. The following code demonstrates that the
reference points to the instance that contains the method:
class ThisTest
{
function thisValue():ThisTest
arrayCountTotal
that tracks the order in which the instances were
arrayNumber
getPosition()
CustomArray.arrayCountTotal
method can refer directly to the static
reference within the body of an instance method is a reference to the
to track the total number of class instances,
that returns the values of these
arrayCountTotal
, code that resides inside the
arrayCountTotal
DESCENDING
static variable
. Code
DESCENDING
using a simple
this
Classes
119

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents