【发布时间】:2009-10-25 10:58:01
【问题描述】:
我在使用 actionscript 定义索引数组时遇到问题。
任务如下。我有一个点对象板。我需要将它们存储到一个数组中,所以我可以简单地使用 x,y 坐标来访问每个点。例如,要获得第一点,我希望能够使用点 [1] [1] 等。我在这里阅读了文档http://livedocs.adobe.com/flex/3/html/help.html?content=10_Lists_of_data_2.html,并意识到我不明白如何根据需要初始化数组。 (特别是当它可以包含 10 到 15 行和列时,因此很难使用以下表示法:masterTaskList[0] = [“洗盘子”,“取出垃圾”];,如文档中所建议的那样。)
我正在做的是:
for (var x:Number = 1; x<= boardSize; x++)
{
for (var y:Number = 1; y<= boardSize; y++)
{
var stone:StoneSprite = new StoneSprite();
stone.x = this.x + x*cellWidth;
stone.y = this.y + y*cellWidth;
stones[x][y] = stone;
}
}
但它给了我一个错误:
RangeError: Index '1' specified is out of bounds. at mx.collections::ListCollectionView/getItemAt()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:422] at mx.collections::ListCollectionView/http://www.adobe.com/2006/actionscript/flash/proxy::getProperty()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:698] at components::Board/placeStonesInNodes()[/Users/oleg/jin/goclub/trunk/goapp/usersList/src/components/Board.as:60] at components::Board/creationComplete()[/Users/oleg/jin/goclub/trunk/goapp/usersList/src/components/Board.as:44] at flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent()
【问题讨论】:
-
请编辑问题并使用代码块而不是引号块。您使用的引用块使其难以阅读。
-
刚试过。不确定它是否有帮助?
标签: apache-flex actionscript-3 arrays