AS3: Packages

In ActionScript 3, you must use the package definition keyword when defining a class. Instead of adding the class path to the class definition, you now add it after the package definition keyword. Within the package definition, you identify the class keyword followed by the class name.

package com.yourcompanyname.utilities
{
class StringUtils
{
}
}

If your class does not have a class path, simply wrap the class in a package definition.

package
{
class StringUtils
{
}
}
Note that Flash allows AS3 class paths to be verified, although not AS2 class paths.
Figure 1 . Verifying class paths in Flash when using AS3.

Figure 2. You are alerted with a warning if Flash cannot find the class.

 

In ActionScript 3, packages are still used to organize your code, but they are now true package definitions, which allow you to define whether or not the classes within the package are accessible by external packages, based on the class attributes.

,

No comments yet.

Leave a Reply