To include an external display asset in an ActionScript
application at compile-time, we use the
[Embed] metadata tag. This tag adds a
specified external asset to a .swf file, and makes that asset accessible
to a program as a user-specified or autogenerated class. Instances of
the embedded asset are created from that class using ActionScript's
standard new syntax.
[Embed] metadata tag is
supported by Flex Builder 2 and the command-line compiler,
mxmlc. However, the
[Embed] metadata is not supported by Adobe
Flash CS3. Future versions of the Flash authoring tool might add
[Embed], we must give
the compiler access to the Flex compiler-support library, flex.swc. By default, all Flex Builder 2
projects automatically include flex.swc in the ActionScript library path,
so in Flex Builder 2, the techniques covered in this section work
without any special compiler configuration.
Unlike the runtime asset-loading techniques we've seen so far
in this chapter, embedding a display asset at compile time using the
[Embed] metadata tag increases
the size of the .swf file loading the asset and also increases the Flash runtime's memory usage. Consequesntly, you should embed an asset at compile time only when you are certain that the application will definitely need to use that asset. Otherwise, you should load the asset at runtime if and when it is required. For example, imagine a product ...