03.05.2013 Views

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

class Vehicle {<br />

var numDoors:Number;<br />

var color:String;<br />

function Vehicle(param_numDoors:Number, param_color:String) {<br />

this.numDoors = param_numDoors;<br />

this.color = param_color;<br />

}<br />

function start():Void {<br />

trace("[Vehicle] start");<br />

}<br />

function stop():Void {<br />

trace("[Vehicle] stop");<br />

}<br />

function reverse():Void {<br />

trace("[Vehicle] reverse");<br />

}<br />

}<br />

The following example shows a second AS file, called Car.as, in the same directory. This class<br />

extends the Vehicle class, modifying it in three ways. First, the Car class adds a variable<br />

fullSizeSpare to track whether the car object has a full-size spare tire. Second, it adds a new<br />

method specific to cars, activateCarAlarm(), that activates the car's anti-theft alarm. Third,<br />

it overrides the stop() function to add the fact that the Car class uses an anti-lock braking<br />

system to stop.<br />

class Car extends Vehicle {<br />

var fullSizeSpare:Boolean;<br />

function Car(param_numDoors:Number, param_color:String,<br />

param_fullSizeSpare:Boolean) {<br />

this.numDoors = param_numDoors;<br />

this.color = param_color;<br />

this.fullSizeSpare = param_fullSizeSpare;<br />

}<br />

function activateCarAlarm():Void {<br />

trace("[Car] activateCarAlarm");<br />

}<br />

function stop():Void {<br />

trace("[Car] stop with anti-lock brakes");<br />

}<br />

}<br />

The following example instantiates a Car object, calls a method defined in the Vehicle class<br />

(start()), then calls the method overridden by the Car class (stop()), <strong>and</strong> finally calls a<br />

method from the Car class (activateCarAlarm()):<br />

var myNewCar:Car = new Car(2, "Red", true);<br />

myNewCar.start(); // output: [Vehicle] start<br />

myNewCar.stop(); // output: [Car] stop with anti-lock brakes<br />

myNewCar.activateCarAlarm(); // output: [Car] activateCarAlarm<br />

180 ActionScript language elements

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!