User Guide
Classes 125
}
return retDay;
}
var dayOfWeek:Day = getDay();
You can also enhance the Day class so that it associates an integer with each day of the week,
and provides a
toString() method that returns a string representation of the day. You might
want to enhance the Day class in this manner as an exercise.
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.
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 project’s build path. When the 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 instance:
<<below code sample was double conditioned to FlexOnly+No Trans. I had to emove
FlexOnly for Flex 2.0.1 loc prodeuction. Since this book is in Flex 2.0.1 location and should
not be used for Flash-MN>>
package
{
import flash.display.Sprite;
import flash.media.SoundChannel;
import mx.core.SoundAsset;
public class SoundAssetExample extends Sprite
{
[Embed(source="sound1.mp3")]
public var soundCls:Class;
public function SoundAssetExample()
{
var mySound:SoundAsset = new soundCls() as SoundAsset;