O'Reilly logo

Essential ActionScript 3.0 by Colin Moock

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Embedding Display Assets at Compile Time

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.

Tip

The [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 support for [Embed].

To use [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.

A Note on File Size and Memory Consumption

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required