0
votes

Got some external classes, say MyClass.as

MyClass.as has a static variable called foo

So, ordinarily in other AS files I can call this with

MyClass.foo = bar;

However, this seems to be different in timeline scripts.

Every time I try this I get the reference with a static type error

1119: Access of possibly undefined property foo through a reference with static type flash.display:DisplayObjectContainer.

I've tried doing an import MyClass, etc... nothing seems to be firing.

Any tips?

1
It works for me. How did you declare your static variable? - David
It seems like AS3 objects to assigning a stage instance directly to a static variable. When I created a non-static variable to represent the stage instance, and then assigned that variable to the static one in the constructor, the error went away. I am running with Auto-Declare stage instances turned off, so there are some unusual rules to abide by. I think this may be closed. - M. Ryan

1 Answers

0
votes

This problem is caused when you have the compile option "Automatically Declare Stage Instances" turned off, which I commonly do. You cannot assign a stage instance to a static variable directly. Instead you must create an instance variable, and then assign it to a static variable in the constructor.

I cannot think of a more elaborate/clean solution than this.

There are some projects where turning on Auto-declare is not an option.