Referencing an movieclip with the same name in an array
I realise this is very basic but i need a quick way of referencing all my objects in an array, I have a series of movieclips with instance names "block1" "block2"... etc.
I there a quick way to reference these in an array something like "block"+1 ? o开发者_开发技巧r even "block" then 1 to 12 ?
Cheers
Not exactly sure what your asking, but if you want to populate an array with references to your movieclips (that are name sequentially), then you can use the getChildByName() method. This method takes an instance name as a string, and gives you back the reference to the displayobject if it finds one. So you could do something like this:
for (var i:int = 1; i <= 12; i++) {
var item:DisplayObject = this.getChildByName('block' + i);
// Use item here. You probably want to make sure item is not null first.
}
精彩评论