User Guide

Inheritance 137
The only way to access the static variable test is through the class object, as shown in the
following code:
Base.test;
It is permissible, however, to define an instance property using the same name as a static
property. Such an instance property can be defined in the same class as the static property or
in a subclass. For example, the Base class in the preceding example could have an instance
property named
test. The following code compiles and executes because the instance
property is inherited by the Extender class. The code would also compile and execute if the
definition of the test instance variable is moved, but not copied, to the Extender class.
package
{
import flash.display.MovieClip;
public class StaticExample extends MovieClip
{
public function StaticExample()
{
var myExt:Extender = new Extender();
trace(myExt.test); // output: instance
}
}
}
class Base
{
public static var test:String = "static";
public var test:String = "instance";
}
class Extender extends Base {}
Static properties and the scope chain
Although static properties are not inherited, they are within the scope chain of the class that
defines them and any subclass of that class. As such, static properties are said to be in scope of
both the class in which they are defined and any subclasses. This means that a static property
is directly accessible within the body of the class that defines the static property and any
subclass of that class.
The following example modifies the classes defined in the previous example to show that the
static
test variable defined in the Base class is in scope of the Extender class. In other words,
the Extender class can access the static
test variable without prefixing the variable with the
name of the class that defines
test.
package
{