User Guide
136 Object-Oriented Programming in ActionScript
package
{
import flash.display.MovieClip;
public class OverrideExample extends MovieClip
{
public function OverrideExample()
{
trace(currentLabel)
}
override public function get currentLabel():String
{
var str:String = "Override: ";
str += super.currentLabel;
return str;
}
}
}
The output of the trace() statement in the OverrideExample class constructor is Override:
null
, which shows that the example was able to override the inherited currentLabel
property.
Static properties not inherited
Static properties are not inherited by subclasses. This means that static properties cannot be
accessed through an instance of a subclass. A static property can be accessed only through the
class object on which it is defined. For example, the following code defines a base class named
Base and a subclass that extends Base named Extender. A static variable named
test is defined
in the Base class. The code as written in the following excerpt does not compile in strict mode
and generates a run-time error in standard mode.
package {
import flash.display.MovieClip;
public class StaticExample extends MovieClip
{
public function StaticExample()
{
var myExt:Extender = new Extender();
trace(myExt.test); // error
}
}
}
class Base {
public static var test:String = "static";
}
class Extender extends Base { }