Specifications

CHAPTER 4
68
Using run-time stylesheets
Using Runtime Shared Libraries (RSLs)
Loading assets at run time rather than embedding them
This section describes loading assets at run time. For information about modules and run-time stylesheets, see
the Adobe Flex 3 Developer Guide. For information about RSLs, see “Using RSLs to reduce SWF file size on
page 70.
One method of reducing the SWF file size is to externalize assets; that is, to load the assets at run time rather than
embed them at compile time. You can do this with assets such as images, SWF files, and sound files.
Embedded assets load immediately, because they are already part of the Flex SWF file. However, they add to the
size of your application and slow down the application initialization process. Embedded assets also require you to
recompile your applications whenever your asset changes.
The following example embeds the shapes.swf file into the Flex application at compile time:
<?xml version="1.0"?>
<!-- optimize/EmbedAtCompileTime.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Image source="@Embed(source='../assets/butterfly.gif')"/>
</mx:Application>
The following example loads the shapes.swf file into the Flex application at run time:
<?xml version="1.0"?>
<!-- optimize/EmbedAtRunTime.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Image source="../assets/butterfly.gif"/>
</mx:Application>
The only supported image type that you cannot load at run time is SVG. Flash Player and AIR require that the
compiler transcodes that file type at compile time. The player and AIR runtime cannot transcode that file type at
run time.
When you load SWF files from domains that are not the same as the loading SWF file, you must use a cross-
domain.xml file or other mechanism to enable the proper permissions. For more information on using the cross-
domain.xml file, see “Using cross-domain policy files” on page 40.
An alternative to reducing SWF file sizes by externalizing assets is to increase the SWF file size by embedding
assets. By embedding assets such as images, sounds, and SWF files, you can reduce the network bandwidth and
connections. The SWF file size increases, but the application requires fewer network connections to the server.
For information on loading assets, see “Embedding Assets” on page 965 in the Adobe Flex 3 Developer Guide.