You compile a custom component so that you can use it as part of your application. You can compile the component when you compile the entire application, or you can compile it separately so that you can link it into the application at a later time.
When you create a Flex component, you can distribute it in one of several different file formats, as the following table shows:
|
File format |
Extension |
Description |
|---|---|---|
|
MXML |
.mxml |
A component implemented as an MXML file. |
|
ActionScript |
.as |
A component implemented as an ActionScript class. |
|
SWC |
.swc |
A component implemented as an MXML or ActionScript file, and then packaged as a SWC file. A SWC file contains components that you package and reuse among multiple applications. The SWC file is then compiled into your application when you create the application's SWF file. |
|
RSL |
.swc |
A component implemented as an MXML or ActionScript file, and then deployed as an RSL. An RSL is a stand-alone file that is downloaded separately from your application's SWF file, and cached on the client computer for use with multiple application SWF files. |
You must take into consideration the file format and file location when you compile an application that uses the component.
Adobe Flex includes two compilers: mxmlc and compc. You use the mxmlc compiler to compile MXML, ActionScript, SWC, and RSL files into a single SWF file. After your application is compiled and deployed on your web or application server, a user can make an HTTP request to download and play the SWF file on their computer.
You use the compc compiler to compile components, classes, and other files into SWC files or into RSLs.
You can use the compc and mxmlc compilers from Adobe® Flex® Builder™ or from a command line. For more information on using the compilers, see Using the Flex Compilers, and Building Projects.
The most basic example of using the mxmlc compiler is one in which the MXML file has no external dependencies (such as components in a SWC file or ActionScript classes). In this case, you open mxmlc and point it to your MXML file:
$ mxmlc c:/myfiles/app.mxml
The default option is the target file to compile into a SWF file, and it must have a value. If you use a space-separated list as part of the options, you can terminate the list with a double hyphen before adding the target file, as in the following example:
$ mxmlc -option arg1 arg2 arg3 -- target_file.mxml
The Flex compilers use a case-sensitive file lookup on all file systems. On case-insensitive file systems, such as the Macintosh and Windows file systems, the Flex compiler generates a case-mismatch error when you use a component with the incorrect case. On case-sensitive file systems, such as the UNIX file system, the Flex compiler generates a component-not-found error when you use a component with the incorrect case.
Typically, you put component files in directories that are in the ActionScript source path. These include your application's root directory, its subdirectories, and any directory that you specify to the compiler. To specify a directory, you use the source-path option to the mxmlc compiler, or the Project Properties dialog box in Flex Builder.
The following rules can help you organize your custom components: