Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flash AS3-访问未定义的属性(静态变量)_Flash_Actionscript 3 - Fatal编程技术网

Flash AS3-访问未定义的属性(静态变量)

Flash AS3-访问未定义的属性(静态变量),flash,actionscript-3,Flash,Actionscript 3,我试图更改类构造函数中的静态变量。首先,我有: public static var mainReference:Main; public static var timerReference:Timer; public var timer:Timer = new Timer(1000); 这样我的静态函数就可以访问main和timer。在Main的构造函数中,我有: mainReference = this; timerReference = timer; 问题是,第一个在我编译它时没有给出错

我试图更改类构造函数中的静态变量。首先,我有:

public static var mainReference:Main;
public static var timerReference:Timer;
public var timer:Timer = new Timer(1000);
这样我的静态函数就可以访问main和timer。在Main的构造函数中,我有:

mainReference = this;
timerReference = timer;

问题是,第一个在我编译它时没有给出错误,但是第二个告诉我访问未定义的属性(timerReference)。

flash player试图将
timerReference
作为类变量而不是静态变量访问,这可能与此有关

试试这个:

this.mainReference = this;
Main.timerReference = this.timer;

现在,您告诉flash player以类变量的形式显式访问
mainReference
,以静态类变量的形式显式访问
timerReference

如果您在构造函数中改为使用timerReference=new Timer(1000)怎么办?为什么?对我来说,在类的每个实例中初始化静态变量听起来不是一个好主意。@RIAstar肯定不是在每个类中都这样做。我打赌他只是想要一个对document类的全局访问,就像一个单身汉一样。但是
timerReference
是非常无用的,因为
timer
是公共的,可以通过
Main.mainReference.timer
@ancide:Oh!我从来没想过!Thanks@Ancide@Marty如果OP仅对类的第一个实例执行此操作,则程序将依赖于实例化顺序。下一个开发者进来了;他在不知不觉中改变了对象的创建顺序;节目中断了。