引用存储在数组中的Sprite / Objects

时间:2012-10-09 09:59:14

标签: actionscript-3

通过push()将对象添加到数组后,如何引用它的xy值?例如:

var Test:Sprite = new Sprite();         
Test.graphics.beginFill(0x000000);
Test.graphics.drawRect(0,0,10,10);
testHolder.addChildAt(genericBlock,0);

1 个答案:

答案 0 :(得分:1)

可以通过以下方式访问存储在数组中的任何对象的xy值:

var myArray = new Array();
myArray.push(testSprite1); // First object 'pushed' into array at position 0
myArray.push(testSprite2); // Second object 'pushed' into array at position 1

myArray[0].x = 50; // testSprite1.x = 50
myArray[1].x = 100; // testSprite2.x = 100;

// To referece..
trace(myArray[0].x, myArray[1].x); // Outputs: 50 100

这是一个很好的教程,可以学习如何实现数组并操纵其中包含的所有/单个元素:

http://www.republicofcode.com/tutorials/flash/as3arrays/