i have code like this in actionscript3,
JavaScript
x
18
18
1
var map: Array = [
2
[[0,1,0],[0,1,0]],
3
[[0,1,0], [0,1,0]]];
4
var nom1: int = 0;
5
var nom2: int = 0;
6
var nom3: int = 1;
7
var nom4: int = 18;
8
stage.addEventListener (Event.ENTER_FRAME, beff);
9
function beff (e: Event): void
10
{
11
map[nom1][nom2][nom3] = nom4
12
}
13
stage.addEventListener (MouseEvent.CLICK, brut);
14
function brut(e: MouseEvent):void
15
{
16
trace (map)
17
}
18
when run, it gets an error in its output
what I want is to fill in each “1” value and not remove the “[” or “]” sign
so when var nom1, var nom2 are changed
Then the output is
JavaScript
1
3
1
[[[0,18,0],[0,18,0]],
2
[[0,18,0],[0,18,0]]]
3
please helps for those who can solve this problem
Advertisement
Answer
If what you want to achieve is to replace every 1 by 18 in this nested array, you could try :
JavaScript
1
12
12
1
for (var i = 0; i < map.length; i++) {
2
var secondLevel = map[i];
3
for (var j = 0; j < secondLevel.length; j++) {
4
var thirdLevel = secondLevel[j];
5
for (var k = 0; k < thirdLevel.length; k++) {
6
if (thirdLevel[k] === 1) {
7
thirdLevel[k] = 18;
8
}
9
}
10
}
11
}
12
Note that, this would only work for nested arrays with 3 levels of depth