User Guide

Packages and namespaces 47
Using namespaces
You can find a real-world example of a namespace that is used to prevent name conflicts in the
flash.utils.Proxy class that is part of the Flash Player API. The Proxy class, which is the
replacement for the
Object.__resolve property from ActionScript 2.0, allows you to
intercept references to undefined properties or methods before an error occurs. All of the
methods of the Proxy class reside in the
flash_proxy namespace in order to prevent name
conflicts.
To better understand how the
flash_proxy namespace is used, you need to understand how
to use the Proxy class. The functionality of the Proxy class is available only to classes that
inherit from it. In other words, if you want to use the methods of the Proxy class on an object,
the object’s class definition must extend the Proxy class. For example, if you want to intercept
attempts to call an undefined method, you would extend the Proxy class and then override the
callProperty() method of the Proxy class.
You may recall that implementing namespaces is usually a three-step process of defining,
applying, and then referencing a namespace. Because you never explicitly call any of the Proxy
class methods, however, the
flash_proxy namespace is only defined and applied, but never
referenced. The Flash Player API defines the
flash_proxy namespace and applies it in the
Proxy class. Your code only needs to apply the
flash_proxy namespace to classes that extend
the Proxy class.
The
flash_proxy namespace is defined in the flash.utils package in a manner similar to the
following:
package flash.utils
{
public namespace flash_proxy;
}
The namespace is applied to the methods of the Proxy class as shown in the following excerpt
from the Proxy class:
public class Proxy
{
flash_proxy function callProperty(name:*, ... rest):*
flash_proxy function deleteProperty(name:*):Boolean
...
}
As the following code shows, you must first import both the Proxy class and the flash_proxy
namespace. You must then declare your class such that it extends the Proxy class (you must
also add the
dynamic attribute if you are compiling in strict mode). When you override the
callProperty() method, you must use the flash_proxy namespace.
package
{