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.

A subclass of the Vehicle class can also be written using the keyword super, which the subclass<br />

can use to access properties <strong>and</strong> methods of the superclass. The following example shows a<br />

third AS file, called Truck.as, again in the same directory. The Truck class uses the super<br />

keyword in the constructor <strong>and</strong> again in the overridden reverse() function.<br />

class Truck extends Vehicle {<br />

var numWheels:Number;<br />

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

param_numWheels:Number) {<br />

super(param_numDoors, param_color);<br />

this.numWheels = param_numWheels;<br />

}<br />

function reverse():Void {<br />

beep();<br />

super.reverse();<br />

}<br />

function beep():Void {<br />

trace("[Truck] make beeping sound");<br />

}<br />

}<br />

The following example instantiates a Truck object, calls a method overridden by the Truck<br />

class (reverse()), then calls a method defined in the Vehicle class (stop()):<br />

var myTruck:Truck = new Truck(2, "White", 18);<br />

myTruck.reverse(); // output: [Truck] make beeping sound [Vehicle] reverse<br />

myTruck.stop(); // output: [Vehicle] stop<br />

See also<br />

class statement<br />

for statement<br />

for(init; condition; next) {<br />

statement(s);<br />

}<br />

Evaluates the init (initialize) expression once <strong>and</strong> then starts a looping sequence. The<br />

looping sequence begins by evaluating the condition expression. If the condition<br />

expression evaluates to true, statement is executed <strong>and</strong> the next expression is evaluated. The<br />

looping sequence then begins again with the evaluation of the condition expression.<br />

The curly braces ({}) used to enclose the block of statements to be executed by the for<br />

statement are not necessary if only one statement will execute.<br />

Statements 181

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

Saved successfully!

Ooh no, something went wrong!