EasyManua.ls Logo

MACROMEDIA FLASH 8-FLASH LITE 2.X ACTIONSCRIPT LANGUAGE - Page 194

MACROMEDIA FLASH 8-FLASH LITE 2.X ACTIONSCRIPT LANGUAGE
780 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
194 ActionScript language elements
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
fullSizeSpare to track whether the car object has a full-size spare tire. Second, it adds a new
method specific to cars,
activateCarAlarm(), that activates the car's anti-theft alarm. Third,
it overrides the
stop() function to add the fact that the Car class uses an anti-lock 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");
}
}

Table of Contents

Related product manuals