User Guide
26 Using ActionScript to Create Components
Your package statement must wrap the entire class definition. If you write your ActionScript
class file to the same directory as your other application files, you can leave the package name
blank. However, as a best practice, you should store your components in a subdirectory, where
the package name reflects the directory location. In this example, your write your
ActionScript class file to the directory myComponents, a subdirectory of your main
application directory.
Formatters are a particular type of component. You might also create a subdirectory of your
application’s root directory called myFormatters for all of your custom formatter classes. Each
formatter class would then define its
package statement, as the following example shows:
package myFormatters
{
// Formatter class definition goes here.
}
If you create a component that is shared among multiple applications, or a component that
might be used with third-party components, assign a unique package name to avoid naming
conflicts. For example, you might prefix your package name with your company name, as in:
package Acme.myFormatters
{
// Formatter class definition goes here.
}
When you reference a custom component from an MXML file, you specify a namespace
definition for the component that corresponds to its directory location and package name, as
the following example shows:
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:MyComp="myFormatters.*">
<!-- Declare a formatter and specify formatting properties. -->
<MyComp:SimpleFormatter id="upperFormat" formatString="upper"/>
...
</mx:Application>
If a formatter class is in a subdirectory of myFormatters, such as myFormatters/
dataFormatters, the package statement is as follows:
package myFormatters.dataFormatters
{
// Formatter class definition goes here.
}