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

Applied Namespace Examples

This chapter's introduction cited four practical scenarios for namespace use:

  • Prevent naming conflicts

  • Framework-level member visibility

  • Permission-based access control

  • Program modes

In the preceding section we learned how namespaces prevent naming conflicts. In this section we'll explore each of the remaining three scenarios with a real-world example.

Example: Framework-Internal Visibility

Our first applied namespace example comes from Adobe's Flex framework, a library of user interface components and utilities for rich Internet application development.

The Flex framework contains a lot of code—hundreds of classes in dozens of packages. Some methods and variables in those classes must be accessible across different packages but are still considered internal to the overall framework. This presents a dilemma: if the methods and variables are declared public, then code outside the framework will have unwanted access to them, but if they are declared internal, they cannot be shared across packages.

To address this issue, the Flex framework defines the namespace mx_internal, and uses it to qualify methods and variables that should not be used outside the framework but must be accessible across different packages within the framework.

Here's the declaration of the mx_internal namespace:

package mx.core {
  public namespace mx_internal =
      "http://www.adobe.com/2006/flex/mx/internal";
}

Let's look at a specific mx_internal example from the Flex framework.

To work with grids ...

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