apscience
apscience

Reputation: 7253

AS3 - Access of undefined property (Static variable)

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);

This 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).

Upvotes: 4

Views: 1677

Answers (1)

rzetterberg
rzetterberg

Reputation: 10268

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.

Upvotes: 5

Related Questions