MACROMEDIA FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE Reference page 209

Actionscript 2.0 language reference
Table of Contents

Advertisement

The following example instantiates a Car object, calls a method that is defined in the Vehicle
class (
), then calls the method that is overridden by the Car class (
start()
finally calls a method from the Car class (
var myNewCar:Car = new Car(2, "Red", true);
myNewCar.start(); // output: [Vehicle] start
myNewCar.stop(); // output: [Car] stop with anti-lock brakes
myNewCar.activateCarAlarm(); // output: [Car] activateCarAlarm
A subclass of the Vehicle class can also be written by using the keyword
subclass can use to access properties and methods of the superclass. The following example
shows a third AS file, called Truck.as, again in the same directory. The Truck class uses the
keyword in the constructor and again in the overridden
super
class Truck extends Vehicle {
var numWheels:Number;
function Truck(param_numDoors:Number, param_color:String,
param_numWheels:Number) {
super(param_numDoors, param_color);
this.numWheels = param_numWheels;
}
function reverse():Void {
beep();
super.reverse();
}
function beep():Void {
trace("[Truck] make beeping sound");
}
}
The following example instantiates a Truck object, calls a method overridden by the Truck
class (
), and then calls a method defined in the Vehicle class (
reverse()
var myTruck:Truck = new Truck(2, "White", 18);
myTruck.reverse(); // output: [Truck] make beeping sound [Vehicle] reverse
myTruck.stop(); // output: [Vehicle] stop
See also
class statement
activateCarAlarm()
), and
stop()
):
, which the
super
function.
reverse()
):
stop()
Statements
209

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