User Guide

Compiling components with Flex 2 SDK 69
Distributing a component as an ActionScript file
When you distribute a component defined as an ActionScript file, you can store it within the
same directory structure as your application files, or in a directory specified in the
ActionScript classpath.
The MXML tag name for a custom component consists of two parts: the namespace prefix
and the tag name. The namespace prefix tells Flex where to look for the file that implements
the custom component. The tag name corresponds to the filename of the component, in this
case MySimpleFormatter.as. Therefore, a file MySimpleFormatter.as defines a component
with the tag name of
<namespace:MySimpleFormatter>.
The main application MXML file defines the namespace prefix used to reference the
component in the
<mx:Application> tag. When you deploy your formatter as an
ActionScript file, you refer to it in one of the following ways:
If you store the formatter component in the same directory as the application file, or in a
directory that the ActionScript classpath (not a subdirectory) specifies, you define the
formatter by using an empty
package statement, as the following example shows:
package
{
//Import base Formatter class.
import mx.formatters.Formatter
public class MySimpleFormatter extends Formatter {
...
}
}
You can refer to it as the following example shows. In this example, the local namespace
(*) is mapped to the prefix MyComp.
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:MyComp="*">
<MyComp:MySimpleFormatter/>
</mx:Application>
If the same file exists in the ActionScript classpath directory and the application directory,
Flex uses the file in the application directory.
If you store the formatter component in a subdirectory of the directory that contains the
application file, you specify that directory as part of the
package statement, as the
following example shows:
package myComponents.formatters
{
//Import base Formatter class