这是从达人翻译的文章中截的,不过源程序有错误,偶改了一下。顺手挂上原教程和源文件(这可是一颗一颗看着flashPaper打的啊!)。上次听的一个c#的讲座,用的也是这个vehicle和car;呵呵,看如何用class驱动我们可爱的flash。
工程有两个类:Vehicle(superClass)和Car(subClass);
class Vehiche{
private var _nPassengers:Number;
public var _nMiles:Number;
public var _nInterval:Number;
function Vehicle(nPassengers:Number,nMiles:Number) {
_nPassengers=nPassengers;
_nMiles=nMiles;
}
...................}
class Car extends Vehiche{
private var _sMake:String;
private var _sMode1:String;
private var _nYear:Number;
function Car(sMake:String ,sMode1:String,nYear:Number,class Car extends Vehiche{
private var _sMake:String;
private var _sMode1:String;
private var _nYear:Number;
function Car(sMake:String ,sMode1:String,nYear:Number,nPassengers:Number,nMiles:Number) {
super.Vehicle(nPassengers,nMiles);//超类
//_nPassengers=nPassengers;
//_nMiles=nMiles;
_sMake=sMake;
_sMode1=sMode1;
year=nYear;
}Number,nMiles:Number) {
super(nPassengers,nMiles);
_sMake=sMake;
_sMode1=sMode1;
year=nYear;
}
...................}
这是原文,Car类中的结构函数中要承继Vehicle的结构函数中的nPassengers,nMiles参数。用super(nPassengers,nMiles);
结果我敲完了一run,不行,trace(car.nMiles)=undefined;
细心看完了文档后才清楚了一点super的用法,于是改为
super.Vehicle(nPassengers,nMiles);
结果成功,哈哈,被达人玩了了一通,想想还是本人好好从本质上下手的好,学oop看java吧,呵呵 !
源文件下载:(含源教程)
点击浏览该文件