Developer Guide
Embedded asset classes
ActionScript 3.0 uses special classes, called embedded asset classes, to represent embedded assets. An embedded asset
is an asset, such as a sound, image, or font, that is included in a SWF file at compile time. Embedding an asset instead
of loading it dynamically ensures that it will be available at run time, but at the cost of increased SWF file size.
var piano:PianoMusic = new PianoMusic();
var sndChannel:SoundChannel =;
Using embedded asset classes in Flex
To embed an asset in ActionScript code, use the [Embed] metadata tag. Place the asset in the main source folder or
another folder that is in your projects build path. When the Adobe Flex compiler encounters an Embed metadata
tag, it creates the embedded asset class for you. You can access the class through a variable of data type Class that you
declare immediately following the
[Embed] metadata tag. For example, the following code embeds a sound named
sound1.mp3 and uses a variable named
soundCls to store a reference to the embedded asset class associated with
that sound. The example then creates an instance of the embedded asset class and calls the
play() method on that
import flash.display.Sprite;
import mx.core.SoundAsset;
public class SoundAssetExample extends Sprite
public var soundCls:Class;
public function SoundAssetExample()
var mySound:SoundAsset = new soundCls() as SoundAsset;
var sndChannel:SoundChannel =;
To use the [Embed] metadata tag in an Adobe Flex Builder 2 ActionScript project, you must import any necessary
classes from the Flex framework. For example, to embed sounds, you must import the mx.core.SoundAsset class. To use
the Flex framework, include the file framework.swc in your ActionScript build path. This will increase the size of your
SWF file.
Alternatively, you can embed an asset with the
@Embed() directive in an MXML tag definition. For more infor-
mation, see “About embedding assets” on page 1497 in the Flex Developer’s Guide.
An interface is a collection of method declarations that allows unrelated objects to communicate with one another.
For example, the Flash Player API defines the IEventDispatcher interface, which contains method declarations that
a class can use to handle event objects. The IEventDispatcher interface establishes a standard way for objects to pass
event objects to one another. The following code shows the definition of the IEventDispatcher interface:

Get ADOBE® FLEX® 3: PROGRAMMING ACTIONSCRIPT™ 3.0 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.