MACROMEDIA FLEX 2-MIGRATING APPLICATIONS TO FLEX 2 Bedienungsanleitung Seite 29

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 184
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen
Seitenansicht 28
Initializing variables 29
Doing the latter results in a “Type annotation is not a compile-time constant” error.
Embed
The Embed syntax in ActionScript is [Embed(params)], and this metadata must be used over
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
new operator rather than the attachMovie() and attachSound()
methods.
In Flex 1.x, the
[Embed] metadata was placed before a var, and the var received the linkage ID
that was associated with the asset. In Flex 2, you put the
[Embed] metadata before a class
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
[Embed] can be of type String.
However, this requires you to get the class via the
getDefinitionByName() method. For
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
undefined in ActionScript 2.0, and is almost never undefined in ActionScript 3.0. In
ActionScript 3.0,
undefined is only for use with type Object. Other types can no longer store
the
undefined value. If you assign undefined to other types, it will be coerced into null,
NaN, 0, or false.
Seitenansicht 28
1 2 ... 24 25 26 27 28 29 30 31 32 33 34 ... 183 184

Kommentare zu diesen Handbüchern

Keine Kommentare