Specifications

CHAPTER 4
70
Rather than loading SWF files into the main application with the SWFLoader control, consider having the SWF
files communicate with each other as separate applications. You can do this with local SharedObjects, LocalCon-
nection objects, or with the ExternalInterface API.
Another approach to loading multiple small SWF files rather than one large one is to use the HTML wrapper to
provide a framework for loading the SWF files.
Comparing dynamic and static linking
Most large applications use libraries of ActionScript classes and components. You must decide whether to use
static or dynamic linking when using these libraries in your Flex applications.
When you use static linking, the compiler includes all components, classes, and their dependencies in the appli-
cation SWF file when you compile the application. The result is a larger SWF file that takes longer to download
but loads and runs quickly because all the code is in the SWF file. To compile your application that uses libraries
and to statically link those definitions into your application, you use the
library-path and include-libraries
options to specify the locations of SWC files.
Dynamic linking is when some classes used by an application are left in an external file that is loaded at run time.
The result is a smaller SWF file size for the main application, but the application relies on external files that are
loaded during run time.
To dynamically link classes and components, you compile a library. You then instruct the compiler to exclude that
library’s contents from the application SWF file. You must still provide link-checking at compile time even though
the classes are not going to be included in the final SWF file.
You use dynamic linking by creating component libraries and compiling them with your application by using the
external-library-path, externs, or load-externs compiler options. These options instruct the compiler to
exclude resources defined by their arguments from inclusion in the application, but to check links against them
and prepare to load them at run time. The
external-library-path option specifies SWC files or directories for
dynamic linking. The
externs option specifies individual classes or symbols for dynamic linking. The load-
externs
option specifies an XML file that describes which classes to use for dynamic linking. This XML file has
the same syntax as the file produced by the
link-report compiler option.
For more information about linking, see About linking” on page 196. For more information about compiler
options, see “Using the Flex Compilers” on page 125.
Using RSLs to reduce SWF file size
One way to reduce the size of your applications 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 only once to the client. These shared files are known as Runtime
Shared Libraries (RSLs).