Adobe Flex 2 Create and Extend Components

Page 67

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 classpath of the application. When Flex compiles the application, it also compiles the components included in the application’s ActionScript classpath. You specify the directory location of the shared components by using one of the following methods: Open the Project Properties dialog box, and then select Flex Build Path to set the ActionScript classpath.

Flex Builder

Command-line 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: Open the Project Properties dialog box, and then select Flex Build Path to set the library directories that contain the SWC files.

Flex Builder

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

Command-line compiler

For more information about SWC files, see Chapter 9, “Using the Flex Compilers,” in Building and Deploying Flex 2 Applications, and Chapter 10, “Building Projects,” in Using Flex Builder 2.

Compiling components with Flex 2 SDK

67


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.