Doing the latter results in a "Type annotation is not a compile-time constant" error.
Embed
The Embed syntax in ActionScript is
a variable. The variable should be of type Class; for example:
[Embed(source="holdon.mp3")]
var sndCls:Class;
public function playSound():void {
var snd:flash.media.Sound = new sndCls();
snd.play();
}
This works in a very similar way to what was implemented in Flex 1.x. The main difference is
that instead of typing the embedded variable String, you type it as Class. In addition,
instantiation relies on the
methods.
In Flex 1.x, the
[Embed]
that was associated with the asset. In Flex 2, you put the
definition to associate the class with an asset. This change makes the linkage ID unnecessary;
instead, the asset is manifested to the object model as a class.
For backwards compatibility, the variable associated with an
However, this requires you to get the class via the
example:
[Embed(source="holdon.mp3")]
var sndStr:String;
public function playSound():void {
var sndClass:Class = getDefinitionByName(sndStr);
var snd:flash.media.Sound = new sndCls();
snd.play();
}
Initializing variables
The default values of uninitialized typed variables (and arguments and properties) was always
in ActionScript 2.0, and is almost never
undefined
ActionScript 3.0,
undefined
the
value. If you assign
undefined
,
, or
.
NaN
0
false
[Embed(params)]
operator rather than the
new
metadata was placed before a var, and the var received the linkage ID
is only for use with type Object. Other types can no longer store
undefined
, and this metadata must be used over
attachMovie()
metadata before a class
[Embed]
[Embed]
getDefinitionByName()
in ActionScript 3.0. In
undefined
to other types, it will be coerced into
and
attachSound()
can be of type String.
method. For
,
null
Initializing variables
29