如何动态创建二维数组?

How can I create 2D array dynamically?

我正在尝试创建二维数组,但出现错误。这是我的代码:

var cleanArr:Array = new Array();
for (var i:int = 0; i < arr.length; i++)
{
    cleanArr[i][0] = arr[i].substring(0, 29);
    cleanArr[i][1] = arr[i].substring(29, int.MAX_VALUE);

    trace(cleanArr[i]);
}

我收到这个错误:

TypeError: Error #1010: A term is undefined and has no properties.

at SubtitleLoader/onComplete()[C:\Users\ ... \SubtitleLoader.as:88]

at flash.events::EventDispatcher/dispatchEventFunction()

at flash.events::EventDispatcher/dispatchEvent()

at flash.net::URLLoader/onComplete()

第 88 行:cleanArr[i][0] = arr[i].substring(0, 29);

我该如何解决这个问题?

cleanArr 完全是空的,它不是二维数组。要使其成为二维数组,其中的项目必须是数组。在您的代码中,它们根本不存在。您必须先在给定位置创建一个数组。试试这个:

var cleanArr:Array = new Array();
for (var i:int = 0; i < arr.length; i++)
{
    cleanArr[i] = new Array();
    cleanArr[i][0] = arr[i].substring(0, 29);
    cleanArr[i][1] = arr[i].substring(29, int.MAX_VALUE);

    trace(cleanArr[i]);
}