AS3阵列中的图像

时间:2012-09-04 10:17:36

标签: actionscript-3

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

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

3 个答案:

答案 0 :(得分:1)

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

有关更多数组内容,请参阅this tutorial

答案 1 :(得分:0)

你可以这样使用它。

var myBlock:Array = new Array();
myBlock.push(myBlock1, myBlock2, myBlock3);

答案 2 :(得分: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