如何将以下图像放入数组中,以便我可以将它们称为 myBlock[1]、myBlock[2] 等
var myBlock1:Block = new Block();
var myBlock2:Block = new Block();
var myBlock3:Block = new Block();
如何将以下图像放入数组中,以便我可以将它们称为 myBlock[1]、myBlock[2] 等
var myBlock1:Block = new Block();
var myBlock2:Block = new Block();
var myBlock3:Block = new Block();
var myBlock:Array = new Array(
new Block(),
new Block(),
new Block()
);
有关更多数组内容,请参阅本教程。
或者在一个不错的循环中:
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
你可以像这样使用它。
var myBlock:Array = new Array();
myBlock.push(myBlock1, myBlock2, myBlock3);