Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 135

Programming actionscript 3.0
Table of Contents

Advertisement

The names of the parameters in the override method, however, do not have to match the
names of the parameters in the base class, as long as the number of parameters and the data
type of each parameter matches.
The super statement
When overriding a method, programmers often want to add to the behavior of the superclass
method they are overriding instead of completely replacing the behavior. This requires a
mechanism that allows a method in a subclass to call the superclass version of itself. The
statement provides such a mechanism, in that it contains a reference to the immediate
super
superclass. The following example defines a class named Base that contains a method named
and a subclass of the Base class named Extender that overrides the
thanks()
method. The
Extender.thanks()
package {
import flash.display.MovieClip;
public class SuperExample extends MovieClip
{
public function SuperExample()
{
var myExt:Extender = new Extender()
trace(myExt.thanks()); // output: Mahalo nui loa
}
}
}
class Base {
public function thanks():String
{
return "Mahalo";
}
}
class Extender extends Base
{
override public function thanks():String
{
return super.thanks() + " nui loa";
}
}
Overriding getters and setters
Although you cannot override variables defined in a superclass, you can override getters and
setters. For example, the following code overrides a getter named
defined in the MovieClip class in the Flash Player API.
method uses the
super
thanks()
statement to call
Base.thanks()
currentLabel
Inheritance
.
that is
135

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents