View comments | RSS feed

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 Flash

To embed an asset, first place the asset into a FLA file's library. Next, use the asset's linkage property to provide a name for the asset's embedded asset class. If a class by that name cannot be found in the classpath, a class is automatically generated for you. You can then create an instance of the embedded asset class and use any properties and methods defined or inherited by that class. For example, the following code can be used to play an embedded sound that is linked to an embedded asset class named PianoMusic:

var piano:PianoMusic = new PianoMusic();
var sndChannel:SoundChannel = piano.play();


Flash CS3


Comments


petit said on Sep 5, 2007 at 3:11 PM :
This embedding assets question gives my workflow a hickup.
Some people I cooperate with use the "Embed tag" to embed asssets:
[Embed ( source='myimage.png' ) ]
var Texture:Class;
The result of instantiating Texture is a Bitmap object, which is then used.

When I take their code to CS3 and try to compile, it doesn't like it at all.
I have to import the image to the fla library, export to AS and give it a class name Texture. When i want to use the image, I instantiate Texture, but this time I get a BitmapData object, so I have to rewrite the code that uses the image too.

There's inconcistancy in the asset handling between Flex and CS3 at compile time.

Further, and this has to be a bug, when you instantiate the class representing the image, youhave to give it fake height and width values, like this:
var pic:BitmapData = new Texture( 10, 10 );
These values can be anything. They are never used and should not be, as the real image values are used.
Cor van Dooren said on Mar 24, 2008 at 6:00 AM :
In Flash CS3
I have a library.swf with a movie clip Background_mc in the library I am trying to embed from this swf into another through a class.
In this document class I do:
[Embed(source='library.swf' symbol='Backgroud_mc')] Private var Background_mc:Class; Private var _myBG:MovieClip

Function init():void{
myBG = new Background_mc();
addChild(myBG)
}

This throws an error:
TypeError: Error #1007: Instantiation attempted on a non-constructor.

What am I doing wrong?

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/9.0/main/00000066.html