2015-01-08 138 views
0

之間有什麼區別:AS3的Flex嵌入圖像雪碧

[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()); 

和其中的一個,我應該使用,爲什麼?

回答

2

第一個是指向GRAPHIC類的實例化副本的變量指針。第二個是隱式聲明。

如果您需要對該對象執行進一步的操作,則可以使用該指針。例如...

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});