User Guide

extends 153
extends
Availability
Flash Player 6.
Usage
class className extends otherClassName {}
interface interfaceName extends otherInterfaceName {}
Parameters
className
The name of the class you are defining.
otherClassName The name of the class on which className is based.
interfaceName The name of the interface you are defining.
otherInterfaceName The name of the interface on which interfaceName is based.
Description
Keyword; defines a class that is a subclass of another class; the latter is the superclass. The subclass
inherits all the methods, properties, functions, and so on that are defined in the superclass.
For more information, see “Creating subclasses” on page 55.
Interfaces can also be extended using the
extends keyword. An interface that extends another
interface includes all the original interfaces method declarations.
Example
In the following example, the Car class extends the Vehicle class so that all its methods, properties,
and functions are inherited. If your script instantiates a Car object, methods from both the Car
class and the Vehicle class can be used.
The following example shows the contents of a file called Vehicle.as, which defines the Vehicle
class:
class Vehicle {
var numDoors:Number;
var color:String;
function Vehicle(param_numDoors:Number, param_color:String) {
this.numDoors = param_numDoors;
this.color = param_color;
}
function start():Void {
trace("[Vehicle] start");
}
function stop():Void {
trace("[Vehicle] stop");
}
function reverse():Void {
trace("[Vehicle] reverse");
}
}
CHAPTER 5
ActionScript Core Language Elements