Tuesday, February 19, 2013

Defining namespaces

Namespaces contain one value, the Uniform Resource Identifier (URI), which is sometimes called the namespace name. A URI allows you to ensure that your namespace definition is unique.

You create a namespace by declaring a namespace definition in one of two ways. You can either define a namespace with an explicit URI, as you would define an XML namespace, or you can omit the URI. The following example shows how a namespace can be defined using a URI.

namespace flash_proxy = “http://www.adobe.com/flash/proxy”;

The URI serves as a unique identification string for that namespace. If you omit the URI, as in the following example, the compiler will create an unique internal identification string in place of the URI. You do not have access to this internal identification string.

namespace flash_proxy;
Once you define a namespace, with or without a URI, that namespace cannot be redefined in the same scope. An attempt to define a namespace that has been defined earlier in the same scope results in a compiler error.

If a namespace is defined within a package or a class, the namespace may not be visible to code outside that package or class unless the appropriate access control specifier is used. For example, the following code shows the flash_proxy namespace defined within the flash.util package. As shown in the following example, the lack of an access control specifier means that the flash_proxy namespace would be visible only to code within the flash.util package and would not be visible to any code outside the package.

package flash.util {
     namespace flash_proxy;
}

The following code uses the public attribute to make the flash_proxy namespace visible to code outside the package:


package flash.util {
     public namespace flash_proxy;
}








Programming Actionscript 3. Powered by Blogger.