User Guide
146 Object-Oriented Programming in ActionScript
Unlike fixed property inheritance, however, prototype inheritance does not require the
override keyword if you want to redefine a method in a subclass. For example. if you want to
redefine the
valueOf() method in a subclass of the Object class, you have three options.
First, you can define a
valueOf() method on the subclass’s prototype object inside the class
definition. The following code creates a subclass of Object named Foo and redefines the
valueOf() method on Foo’s prototype object as part of the class definition. Because every
class inherits from Object, it is not necessary to use the
extends keyword.
dynamic class Foo
{
prototype.valueOf = function()
{
return "Instance of Foo";
};
}
Second, you can define a valueOf() method on Foo’s prototype object outside the class
definition, as shown in the following code:
Foo.prototype.valueOf = function()
{
return "Instance of Foo";
};
Third, you can define a fixed property named valueOf() as part of the Foo class. This
technique differs from the others in that it mixes fixed property inheritance with prototype
inheritance. Any subclass of Foo that wants to redefine
valueOf() must use the override
keyword. The following code shows
valueOf() defined as a fixed property in Foo:
class Foo
{
function valueOf() {
return "Instance of Foo";
}
}