Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 49

Programming actionscript 3.0
Table of Contents

Advertisement

The following example uses a user-defined namespace to group together two functions that
reside in different packages. By grouping them into the same namespace, you can make both
functions visible to a class or package through a single
This example uses four files to demonstrate the technique. All of the files must be within your
classpath. The first file, myInternal.as, is used to define the
the file is in a package named example, you must place the file into a folder named example.
The namespace is marked as
// myInternal.as in folder example
package example
{
public namespace myInternal = "http://www.adobe.com/2006/actionscript/
examples";
}
The second and third files, Utility.as and Helper.as, define the classes that contain methods
that should be available to other packages. The Utility class is in the example.alpha package,
which means that the file should be placed inside a folder named alpha that is a subfolder of
the example folder. The Helper class is in the example.beta package, which means that the file
should be placed inside a folder named beta that is also a subfolder of the example folder.
Both of these packages, example.alpha and example.beta, must import the namespace before
using it.
// Utility.as in the example/alpha folder
package example.alpha
{
import example.myInternal;
use namespace myInternal;
public class Utility
{
private static var _taskCounter:int = 0;
public static function someTask()
{
_taskCounter++;
}
myInternal static function get taskCounter():int
{
return _taskCounter;
}
}
}
// Helper.as in the example/beta folder
package example.beta
{
so that it can be imported into other packages.
public
statement.
use namespace
namespace. Because
myInternal
Packages and namespaces
49

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents