1

如何将以下图像放入数组中,以便我可以将它们称为 myBlock[1]、myBlock[2] 等

var myBlock1:Block = new Block();
var myBlock2:Block = new Block();
var myBlock3:Block = new Block();
4

3 回答 3

1
var myBlock:Array = new Array(
    new Block(),
    new Block(),
    new Block()
);

有关更多数组内容,请参阅本教程

于 2012-09-04T10:21:43.980 回答
0

或者在一个不错的循环中:

var blocks:Array = [];
var n:int = 100; // I want a hundred blocks please

for(var i:int = 0; i < n; i++)
{
    var block:Block = new Block();
    block.id = i; // my block class has an id 
    blocks.push(block);
{

// I want block 42 - (or 41 as its 0 based to be pedantic)
trace(blocks[41].id); // my block has id of 42
于 2012-09-04T13:13:28.730 回答
0

你可以像这样使用它。

var myBlock:Array = new Array();
myBlock.push(myBlock1, myBlock2, myBlock3);
于 2012-09-04T12:51:12.550 回答