O'Reilly logo

Essential ActionScript 3.0 by Colin Moock

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Namespaces for Access-Control Modifiers

Just as we use namespaces to control variable and method visibility in our own programs, so ActionScript uses namespaces to control the visibility of every variable and method in every program! Remember the four access-control modifiers in ActionScript—public, internal, protected, private? ActionScript, itself, enforces those visibility rules using namespaces. For example, from ActionScript's perspective, the variable definition:

class A {
  private var p:int;
}

means "create a new variable p qualified by the class A's private namespace."

In each scope, ActionScript implicitly opens the appropriate namespaces for the various access-control modifiers. For example, in every scope ActionScript always adds the global public namespace to the set of open namespaces. At the top level of a package, ActionScript also adds that package's internal and public namespaces. In code within a class that resides in a package, ActionScript also adds the class's private and protected namespaces. The set of open namespaces, then, includes not just user-opened namespaces, but also the access-control namespaces that are implicitly opened by ActionScript in each scope.

Warning

You cannot use the use namespace directive to open one of the access-control namespaces explicitly. ActionScript opens the access-control namespaces automatically according to the current scope.

The access-control modifier namespaces determine the accessibility of identifiers and prevent naming conflicts. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required