Specifications

CHAPTER 10
214
Example of creating and using a standard and cross-domain RSL
This example walks you through the process of creating a library and then using that library as a standard and a
cross-domain RSL with an application. It uses the command-line compilers, but you can apply the same process
to create and use RSLs with a Flex Builder project. This example first shows you how to use a standard RSL, and
then how to use that same RSL as a cross-domain RSL.
Keep in mind that a SWC file is a library that contains a SWF file that contains run-time definitions and additional
metadata that is used by the compiler for dependency tracking, among other things. You can open SWC files with
any archive tool, such as WinZip, and examine the contents.
Before you use an RSL, first learn how to statically link a SWC file. To do this, you build a SWC file and then set
up your application to use that SWC file.
In this example you have an application named app.mxml that uses the ProductConfigurator.as and
ProductView.as classes. The structure of this example includes the following files and directories:
project/src/app.mxml
project/libsrc/ProductConfigurator.as
project/libsrc/ProductView.as
project/lib/
project/bin/
To compile this application without using libraries, you can link the classes in the /libsrc directory using the
source-path option, as the following example shows:
cd project/src
mxmlc -o=../bin/app.swf -source-path+=../libsrc app.mxml
This command adds the ProductConfigurator and ProductView classes to the SWF file.
To use a library rather than standalone classes, you first create a library from the classes. You use the compc
compiler to create a SWC file that contains the ProductConfigurator and ProductView classes, as the following
command shows:
cd project
compc -source-path+=libsrc -debug=false -o=lib/mylib.swc ProductConfigurator ProductView
This compiles the mylib.swc file in the lib directory. This SWC file contains the implementations of the Product-
Configurator and ProductView classes.
To recompile your application with the new library, you add the library with the library-path option, as the
following example shows:
cd project/src
mxmlc -o=../bin/app.swf -library-path+=../lib/mylib.swc app.mxml