[英]how to fill in the value in the array
i have code like this in actionscript3,我在actionscript3中有这样的代码,
var map: Array = [
[[0,1,0],[0,1,0]],
[[0,1,0], [0,1,0]]];
var nom1: int = 0;
var nom2: int = 0;
var nom3: int = 1;
var nom4: int = 18;
stage.addEventListener (Event.ENTER_FRAME, beff);
function beff (e: Event): void
{
map[nom1][nom2][nom3] = nom4
}
stage.addEventListener (MouseEvent.CLICK, brut);
function brut(e: MouseEvent):void
{
trace (map)
}
when run, it gets an error in its output运行时,它的 output 出现错误
what I want is to fill in each "1" value and not remove the "[" or "]" sign我想要的是填写每个“1”值而不是删除“[”或“]”符号
so when var nom1, var nom2 are changed所以当 var nom1, var nom2 改变时
Then the output is那么 output 是
[[[0,18,0],[0,18,0]],
[[0,18,0],[0,18,0]]]
please helps for those who can solve this problem请帮助那些可以解决这个问题的人
If what you want to achieve is to replace every 1 by 18 in this nested array, you could try:如果您想要实现的是将此嵌套数组中的每 1 替换为 18,您可以尝试:
for (var i = 0; i < map.length; i++) {
var secondLevel = map[i];
for (var j = 0; j < secondLevel.length; j++) {
var thirdLevel = secondLevel[j];
for (var k = 0; k < thirdLevel.length; k++) {
if (thirdLevel[k] === 1) {
thirdLevel[k] = 18;
}
}
}
}
Note that, this would only work for nested arrays with 3 levels of depth请注意,这仅适用于具有 3 个深度级别的嵌套 arrays
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.