【发布时间】:2014-04-01 17:31:53
【问题描述】:
在下面的代码中,你能告诉我为什么在调用 b.method() 时 _myVar 为 null 而 g 不为 null 吗?
我正在使用 ActionScript3。
我错过了什么吗?
public Class A{
protected var _myVar:Type;
protected method(){
_myVar // do something with _myVar...
var g:Type = B.stVar;
}
}
public Class B extends A{
public static var stVar:Type;
public B(){
_myVar = stVar;
}
}
public class MainClass{
mainMethod(){
B.stVar = new Type();
var b:B = new B();
b.method(); // here _myVar is null while g is not!!!!
}
}
【问题讨论】:
-
不太确定,但我的猜测是因为 stVar 是一个静态变量。为了让它工作,_myVar 也需要是一个静态变量。您不能将静态值分配给普通属性,反之亦然。
标签: actionscript-3 inheritance static-members