Wednesday, July 28, 2010

Creating a variable in a Flex class that the class can't access

If you use namespaces in Flex classes, it's possible to create a variable or function that isn't accessible from within the class. For example:

package whatever
{
  import path.to.some_namespace;

  some_namespace var bar : String;

  public class Foo()
  {
    bar = "Hello World";
  }
}

Because the class has not declared this:

use namespace some_namespace;

it has no access to its own variable bar, so compiling it gives this error:

Attempted access of inaccessible property bar through a reference with static type whatever:Foo.

I'm sure this can be used in some arcane way to really confuse things in your Flex code.

No comments: