AS3 Flex 将图像嵌入到 Sprite

AS3 Flex Embed Image to Sprite

有什么区别:

[Embed(source = "../assets/graphic.png")]
const GRAPHIC:Class;
var graphic:Bitmap = new GRAPHIC();
addChild(graphic);

并且:

[Embed(source = "../assets/graphic.png")]
const GRAPHIC:Class;
addChild(new GRAPHIC());

我应该使用其中的哪一个,为什么?

第一个是指向 GRAPHIC class 的实例化副本的变量指针。第二个是隐式声明。

如果您需要对对象执行进一步的操作,您将使用指针。例如...

graphic.name = "myGraphic";
graphic.alpha = 0.5;
someFunction(graphic);

设置属性并将其作为参数传递给其他函数是指针的好例子。如果不需要这样做,可以使用隐式声明。当有意义时,您可以在其他地方执行此操作。例如...

var settings:Object = {
    "x":20,
    "alpha":0.5
}
setProperties(foo, settings);

// Instead, you can do it in one line, with an implicit declaration.
setProperties(foo, {"x":20, "alpha":0.5});