« The Ultimate Xbox 360 Launch Party and I’m there!!!!! | Main | [Forehead Slapping Moment] Flvs not Playing »

December 14, 2005

[Flash] Erroneous Flash 8 AS Error when Accessing Static Members

When accessing static members inside of a class I always reference it using the class name to visually identify the variable as a static member (e.g Foo.bar).

This is a naming convention that I have been using for years and the only naming convention for static members that I really like. However, I came across a unique use case where check syntax (ctrl-t on windows) throws a "static members can only be accessed directly through classes." error in Flash 8:

class Foo
{

private static var bar = "bar";

public function getBar()
{
trace(Foo.bar) //error
}

}

After some digging, the problem was that I didn’t define a constructor function (which I shouldn’t have to):

class Foo
{

private static var bar = "bar";

public function Foo(){}

public function getBar()
{
trace(Foo.bar) //works
}

}

Because an error isn’t thrown at compile time and because this issue isn’t present in Flash 7 I am lead to believe that this wasn’t an intentional feature.

(Longest Title Ever)

-erik
comments are still dead, thanks spamers!

Posted by erikbianchi at December 14, 2005 06:25 PM

Comments

Post a comment




Remember Me?