I have an array:
var type:Array = [[[1,2,3], [1,2,3],[1,2,3]],
[[1,2,3], [1,2,3],[1,2,3]]];
Then I loop it to call the a function:
for(var i:int = 0;i<type.length;i++) {
addGrid(type[0][i]);
}
The function that I'm calling is:
public function addGrid(col,row:int, type:Array) {
var newGird:GridE = new GirdE();
newGird.col = col;
newGird.row = row;
newGird.type = type;
}
Hope it clear what i need. My Gird can be a big as the array is for the Array sample in here the Gird would be 3(Columns)x2(Rows)
Florent
12.4k10 gold badges51 silver badges58 bronze badges
asked Oct 25, 2012 at 13:31
-
Sorry, that's not clear. What's the problem?Florent– Florent2012年10月25日 14:00:31 +00:00Commented Oct 25, 2012 at 14:00
-
I need to creat a GIRD form array using the addGird function where i have 3 variables that need to come from the array the col number, the row number and type number. and in the example the array is 3x2 gird at list in my eyes. If you look at the code you should understand the what im trying to achive.user1709407– user17094072012年10月25日 14:03:30 +00:00Commented Oct 25, 2012 at 14:03
1 Answer 1
ActionScript 3 multidimensional arrays may be referenced using multiple array indexes by looping your row and column.
Per your array structure, you first define rows, then columns.
This makes a lookup for cell value:
grid[row][col]
Iterating all elements could be implemented as:
private var grid:Array = [[[ 1, 2, 3 ], [ 1, 2, 3 ], [ 1, 2, 3 ]],
[[ 1, 2, 3 ], [ 1, 2, 3 ], [ 1, 2, 3 ]]];
public function loop()
{
// for every row...
for (var row:uint = 0; row < grid.length; row++)
{
// for every column...
for (var col:uint = 0; col < grid[row].length; col++)
{
// your value of "1, 2, 3" in that cell can be referenced as:
// grid[row][col][0] = 1
// grid[row][col][1] = 2
// grid[row][col][2] = 3
// to pass row, col, and the value array to addGrid function:
addGrid(row, col, grid[row][col]);
}
}
}
public function addGrid(row:int, col:int, value:Array):void
{
/* ... */
}
answered Oct 25, 2012 at 15:58
1 Comment
user1709407
Thanks this works, i found similar answer to this myself, i only used the calling part differently: addGrid(gird[row][col][0], gird[row][col][1], gird[row][col][2]);
default