2011-09-25 47 views
1

所以我試圖加載嵌入的圖像是這樣的:如何使用Flex/ActionScript在內存中加載圖像?

[Bindable] 
[Embed(source="path")] 
private var cls_img:Class; 

var img:Image = new Image(); 
img.source = cls_img; 

現在我試圖複製從它的像素塊,但是我得到一個錯誤img.bitmapData爲null,並且錯誤消失時我用addElement(img)將它添加到應用程序中; 難道不可能強制flex將內容加載到內存中,這樣我就可以在不將它添加到舞臺的情況下對其進行操作?

回答

3

是的 - 您可以使用cls_img作爲BitmapAsset。

[Bindable] 
[Embed(source="path")] 
private var cls_img:Class; 

... 

var asset:BitmapAsset = new cls_img() as BitmapAsset; 
// The asset has a bitmapData property that gives you access to the image data 
img.source = asset; 

欲瞭解更多信息,請查看文檔:

http://livedocs.adobe.com/flex/3/html/help.html?content=embed_4.html

相關問題