开发者

AS3 - Access of undefined property (Static variable)

开发者 https://www.devze.com 2023-03-19 20:31 出处:网络
I\'m trying to change a static variable in the class\'s constructor. At the start I have: public static var mainReference:Main;

I'm trying to change a static variable in the class's constructor. At the start I have:

public static var mainReference:Main;
public static var timerReference:Timer;
public var timer:Timer = new Timer(1000);

Th开发者_运维知识库is is so my static functions can access main and timer. At Main's constructor I have:

mainReference = this;
timerReference = timer;

The problem is, the first gives no error when I compile it, but the second tells me Access of undefined property (timerReference).


It might have something to do that the flash player is trying to access timerReference as a class var instead of a static var.

Try this:

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

Now you are telling flash player to explicitly access mainReference as a class var and timerReference as a static class var.

0

精彩评论

暂无评论...
验证码 换一张
取 消