User Guide

138 Object-Oriented Programming in ActionScript
import flash.display.MovieClip;
public class StaticExample extends MovieClip
{
public function StaticExample()
{
var myExt:Extender = new Extender();
}
}
}
class Base {
public static var test:String = "static";
}
class Extender extends Base
{
public function Extender()
{
trace(test); // output: static
}
}
If an instance property is defined that uses the same name as a static property in the same class
or a superclass, the instance property has higher precedence in the scope chain. The instance
property is said to shadow the static property, which means that the value of the instance
property is used instead of the value of the static property. For example, the following code
shows that if the Extender class defines an instance variable named test, the
trace()
statement uses the value of the instance variable instead of the value of the static variable.
package
{
import flash.display.MovieClip;
public class StaticExample extends MovieClip
{
public function StaticExample()
{
var myExt:Extender = new Extender();
}
}
}
class Base
{
public static var test:String = "static";
}
class Extender extends Base
{
public var test:String = "instance";