views:

348

answers:

1

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?

A: 

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.

Jasconius