2013-02-03 72 views
0

我創建了一個Array,其中包含庫中我的圖像 - 類的名稱。從庫中動態創建圖像-Ojbects

var myArr:Array = new Array("myPic1","myPic2","myPic3"); 

一般來說,如果我想創建我的類的對象,我會

var libraryImage:Bitmap; 
libraryImage = new Bitmap(new myPic1(0,0)); 

但我怎麼可以通過遍歷數組和動態創建我的圖片?

for(var i:uint = 0; i<myArr.length; i++){ 
    var libraryImage:Bitmap; 
    libraryImage = new Bitmap(new myArr[i](0,0)); 
} 

不工作

+0

'新位圖(新myPic1(0,0))'你想讓你的bitmapData沒有高度和寬度? – TheDarkIn1978

回答

0

試試這個:

var myArr:Array = new Array(new myPic1(0,0), new myPic2(0,0), new myPic3(0,0)); 
for(var i:uint = 0; i<myArr.length; i++){ 
    var libraryImage:Bitmap; 
    libraryImage = new Bitmap(myArr[i]); 
} 
0

你可以做這樣的事情

for(var i:uint = 0; i<myArr.length; i++){ 
    var myClass:Class = getDefinitionByName(myArr[i]) as Class; 
    var libraryImage:Bitmap; 
    libraryImage = new Bitmap(new myClass(0,0)); 
}