Tuesday, August 25, 2009

Multidimensional arrays in AS3

To declare a multidimensional array in AS3, we would have to create a loop, so to create for example a 2 dimensional bitmap array the code would be like so:
private var my_array:Array = new Array();

var i:int;
for (i=0; i < 20; i++) {
my_array[i] = new Array();

var j:int;
for (j=0; j < 20; j++) {
my_array[i][j] = new Bitmap();

}
}



Now we have a 20 x 20 bitmap array initialised and you can access the properties and methods of the bitmap like so:
my_array[some value][some value].x = some x value;

No comments:

Post a Comment