MACROMEDIA FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE Reference page 208

Actionscript 2.0 language reference
Table of Contents

Advertisement

Example
In the following example, the Car class extends the Vehicle class so that all of 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");
}
}
The following example shows a second AS file, called Car.as, in the same directory. This class
extends the Vehicle class, modifying it in three ways. First, the Car class adds a variable
to track whether the car object has a full-size spare tire. Second, it adds a new
fullSizeSpare
method specific to cars,
Third, it overrides the
braking system to stop.
class Car extends Vehicle {
var fullSizeSpare:Boolean;
function Car(param_numDoors:Number, param_color:String,
param_fullSizeSpare:Boolean) {
this.numDoors = param_numDoors;
this.color = param_color;
this.fullSizeSpare = param_fullSizeSpare;
}
function activateCarAlarm():Void {
trace("[Car] activateCarAlarm");
}
function stop():Void {
trace("[Car] stop with anti-lock brakes");
}
}
208
ActionScript language elements
activateCarAlarm()
function to add the fact that the Car class uses an antilock
stop()
, which activates the car's antitheft alarm.

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE and is the answer not in the manual?

This manual is also suitable for:

Flash 8

Table of Contents

Save PDF