flash actionscript3.0组建使用
下面的示例显示名为 Vehicle.as 的文件(它定义 Vehicle 类)的内容:
package {
class Vehicle {
var numDoors:Number;
var color:String;
public function Vehicle(param_numDoors:Number = 2, param_color:String = null) {
numDoors = param_numDoors;
color = param_color;
}
public function start():void {
trace("[Vehicle] start");
}
public function stop():void {
trace("[Vehicle] stop");
}
public function reverse():void {
trace("[Vehicle] reverse");
}
}
}
下例说明同一目录中名为 Car.as 的第二个 ActionScript 文件。此类扩展 Vehicle 类,通过三种方式修改它。第一种是 Car 类添加变量 fullSizeSpare 以跟踪 car 对象是否具有标准尺寸的备用轮胎。第二种是它添加特定于汽车的新方法 activateCarAlarm(),该方法用于激活汽车的防盗警报。第三种是它覆盖 stop() 函数以添加 Car 类使用防抱死制动系统来停车的事实。
package {
public class Car extends Vehicle {
var fullSizeSpare:Boolean;
public function Car(param_numDoors:Number, param_color:String, param_fullSizeSpare:Boolean) {
numDoors = param_numDoors;
color = param_color;
fullSizeSpare = param_fullSizeSpare;
}
public function activateCarAlarm():void {
trace("[Car] activateCarAlarm");
}
public override function stop():void {
trace("[Car] stop with antilock brakes");
}
}