2011-09-04 73 views
0

我試圖從嵌入式源圖像加載BitmapImage的,這增加是UIComponent。我附上下面的代碼。我一直無法得到這個工作。任何幫助將不勝感激。添加的BitmapImage到畫布

var bitmap:BitmapImage = new BitmapImage(); 
bitmap.source ="@Embed('sample.jpg')"; 
var graphic:Graphic = new Graphic(); 
graphic.addElement(bitmap); 
thumbHolder.addChild(graphic); 

當我運行此我沒有得到一個錯誤,但沒有圖像顯示在thumbHolder(我UIComponent)。

謝謝

回答

2

使用ActionScript時的嵌入工作方式與MXML中的嵌入方式有所不同。在這種情況下,您將源設置爲字符串(而不是嵌入式圖像)。

// Defined somewhere else in your class 
[Embed(source="sample.jpg")] 
public var embeddedImage:Class; 

// Setting the source the right way 
var bitmap:BitmapImage = new BitmapImage(); 
bitmap.source = embeddedImage; 
var graphic:Graphic = new Graphic(); 
graphic.addElement(bitmap); 
thumbHolder.addChild(graphic); 
+0

非常感謝林戈納嘗試這一點 – jln646v