闪客动漫天地论坛

首页 » Flash专区 » 脚本编程技术 » A Bug Fixed In Flash 8 (Original In Mx 2004)...
Deackie - 2007-11-16 22:55:00
A bug in ActionScript 2.0 prevents access to inherited class properties before the superclass that defines the property is used in a script.
这是EAS2.0中"4.3.1.4 Subclasses and class properties"里面提到过的一个BUG
但是,在Flash 8里面这个BUG已经被补上了哈
於此小小通知一下,嘻嘻

For example, in the following code, the class property Employee.defaultSalary is inherited by Manager:

// Code in Employee.as

class Employee {

  public static var defaultSalary:Number = 34000;

}



// Code in Manager.as

class Manager extends Employee {

}


If, outside of the Employee and Manager classes, we attempt to access Manager.defaultSalary before referencing the Employee class, then the property will be undefined:

// Fails when this code appears outside of Employee.as and Manager.as

trace(Manager.defaultSalary);  // Displays: undefined


To fix the problem, we simply refer to the Employee class before accessing the property:

// Refer to Employee

Employee;

// Now it works

trace(Manager.defaultSalary);  // Displays: 34000


Note, however, that the inherited class property bug does not cause problems for code inside the subclass. For example, the following code in Manager works without any special reference to Employee:

class Manager extends Employee {

  function paySalary ( ):Void {

    // This reference is valid because Employee is referenced

    // in the Manager class definition.

    var salary:Number = Manager.defaultSalary;



    // Remainder of method not shown...

  }

}


上面的是书里面的原话哈
时间比较紧就没有翻译,有空回来译!!!
 1 
查看完整版本: A Bug Fixed In Flash 8 (Original In Mx 2004)...