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

Using a Namespace to Qualify Variable and Method Definitions

Now that we've defined the fruit and color namespaces, we can use them to specify the so-called qualifier namespace for new methods and variables. The qualifier namespace is the namespace within which the variable or method name is unique.

To specify the qualifier namespace for a new variable or method, we use that namespace's identifier as an attribute of the variable or method definition, as follows:

// Specify the qualifier namespace for a variable
namespaceIdentifier var propName:datatype =
optionalInitialValue;

// Specify the qualifier namespace for a method
namespaceIdentifier function methodName (params):ReturnType
 {
  statements
}

The following rules apply to the namespaceIdentifier:

  • It must be accessible to the scope where the variable or method is defined, as discussed later in the section "Namespace Accessibility."

  • It cannot be a literal value; specifically it cannot be a string literal containing a namespace name (URI).

  • It must be a compile-time constant.

These three rules effectively mean that the namespaceIdentifier can only be a namespace identifier created with the namespace keyword, and specifically cannot be a variable that refers to a namespace value. (We'll learn about variables that refer to namespace values later in the section "Assigning and Passing Namespace Values.")

Here's how to specify the qualifier namespace fruit for an instance variable named orange:

fruit var orange:String = "Round citrus fruit";

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