What does this mean for me? You will always be able to play your favorite games on Kongregate. However, certain site features may suddenly stop working and leave you with a severely degraded experience.
What should I do? We strongly urge all our users to upgrade to modern browsers for a better experience and improved security.
We suggest you install the latest version of one of these browsers:
Hi, I’m having trouble understanding AS3 Classes. I would like to store a class into a variable. For example:
Main.as can (import Assets.\*;) and access (public static vars) by referencing them (Assets.Assets.somestaticvariable). All is good.
Main.as can also declare (private static var AA:Class=Assets.Assets;) in its class section and access the same variable above via (AA.somestaticvariable). All still good.
somestaticvariable can be any singleton (int, Number, Sprite, …). However, it cannot be an (Array, Vector, or function). WHY?
Assets.Assets.imgArr.push(…); works, all other .as files referencing this global array are in sync.
AA.imgArr.push(…); blows chunks.
Calling a static function:
AA.somestaticfunction(…); wont even compile.
I’ve also tried to declare AA: (private static var AA:Class=ApplicationDomain.currentDomain.getDefinition(“Assets.Assets”) as Class;) with the appropriate import, and same results as other declaration.
Why are the singletons working, but the array and functions failing? all are declared (public static var).
You cannot call a static function or variable from an instance of an object.
You must do this:
var obj:ClassName = new ClassName();
Making something static means that it doesn’t apply to an instance of this class, but to the class in general.
Think of it as a ‘Human’ class. You declare an instance called ‘var Bob:Human = new Human();’. A non-static variable or function would be specific to Bob, where a static variable or function would be not specific to Bob, but to all instances made from Human. So Bob has a non-static variable called skin colour since it is unique to that instance of human, but has a static function called Reflex since it common and has no differences between any instance of Human (assuming all Human’s have the same reflex with no differences).
I hope that made sense. Just remember that to call static members through the class name xD.