-1

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

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

1 回答 1

1

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

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/

于 2012-10-09T10:01:54.793 回答