Adobe Flex 3 Help

Compiling components with Flex SDK

How you compile an application with Adobe Flex SDK is based on how you distribute your custom components that are distributed as MXML, ActionScript, SWC, and RSL files.

Distributing components as MXML and ActionScript files

When you compile an application with Flex SDK, you define where the MXML and ActionScript files for your custom components exist in the directory structure of your application, or in the directory structure of components shared by multiple applications.

For example, you can create a component for use by a single application. In that case, you store it in the directory structure of the application, usually in a subdirectory under the directory that contains the main file of the application. The component is then compiled with the entire application into the resultant SWF file.

You can also create a component that is shared among multiple applications as an MXML or ActionScript file. In that case, store the component in a location that is included in the ActionScript source path of the application. When Flex compiles the application, it also compiles the components included in the application's ActionScript source path.

You specify the directory location of the shared components by using one of the following methods:

Flex Builder 

Open the Project Properties dialog box, and then select Flex Build Path to set the ActionScript source path.



mxmlc compiler 

Use the source-path option to the mxmlc compiler to specify the directory location of your shared MXML and ActionScript files.



Distributing components as SWC files

A SWC file is an archive file of Flex components. SWC files make it easy to exchange components among Flex developers. You need to exchange only a single file, rather than the MXML or ActionScript files, images, and other resource files. In addition, the SWF file inside a SWC file is compiled, which means that the code is hidden from casual view. Finally, compiling a component as a SWC file can make namespace allocation an easier process.

SWC files can contain one or more components and are packaged and expanded with the PKZIP archive format. You can open and examine a SWC file by using WinZip, JAR, or another archiving tool. However, do not manually change the contents of a SWC file, and do not try to run the SWF file that is in a SWC file outside of the SWC file.

When you compile your application, you specify the directory location of the SWC files by using one of the following methods:

Flex Builder  

Open the Project Properties dialog box, and then select Flex Build Path to set the library directories that contain the SWC files.



mxmlc compiler 

Set the library-classpath option to the mxmlc compiler to specify the directory location of your SWC files.



One of the advantages of distributing components as SWC files is that you can define a global style sheet, named defaults.css, in the SWC file. The defaults.css file defines the default style settings for all of the components defined in the SWC file. For more information, see Applying styles from a defaults.css file.

For more information about SWC files, see Using the Flex Compilers, and Building Projects.

Distributing components as RSLs

One way to reduce the size of your application's SWF file is by externalizing shared assets into stand-alone files that can be separately downloaded and cached on the client. These shared assets are loaded by any number of applications at run time, but must be transferred to the client only once. These shared files are known as Runtime Shared Libraries (RSLs).

If you have multiple applications but those applications share a core set of components or classes, your users download those assets only once as an RSL. The applications that share the assets in the RSL use the same cached RSL as the source for the libraries as long as they are in the same domain. By using an RSL, you can reduce the resulting file size for your applications. The benefits increase as the number of applications that use the RSL increases. If you only have one application, putting components into RSLs does not reduce the aggregate download size, and may increase it.

When you compile your application, you specify the directory location of an RSL file by using one of the following methods:

Flex Builder  

Open the Project Properties dialog box, and then select Flex Build Path to set the library directories that contain the SWC files.



mxmlc compiler  

Set the external-library-path option to the mxmlc compiler to specify the location of the RSL file at compile time. Set the runtime-shared-libraries option to the mxmlc compiler to specify the relative location of the RSL file when the application is deployed.



For more information, including information on how to create an RSL file, see Using Runtime Shared Libraries.