我试着做一个多维数组,但我得到一个错误(类型错误:错误#1010:A项是不确定的,没有属性)。
Im trying to make a multidimensional array but I obtain an error ("TypeError: Error #1010: A term is undefined and has no properties.").
var matriz:Array = new Array();
for(var p:Number = 0; p<2;p++ ){
for(var q:Number = 0; q<2;q++ ){
matriz[p][q] = 0;
}
}
我是什么做错了吗?
what am I doing wrong?
在此先感谢!
您需要创建 matriz [P]
,然后才能添加阵列(或任何内部数组其他人)进去。
You need to create an array within matriz[p]
before you can add an array (or anything else) into it.
您可以实现你没有尝试这样的错误是什么:
You can achieve what you're attempting without errors like this:
var matriz:Array = [];
for(var p:Number = 0; p<2; p++)
{
// Create an array at matriz[p] if undefined.
if(matriz[p] == undefined) matriz[p] = [];
for(var q:Number = 0; q<2; q++)
{
matriz[p][q] = 0;
}
}
从本质上讲,你试图做一样的:
Essentially you were trying to do the same as this:
var object:Object = {};
object.nonexistantProperty.value = 10;