Skip to main content
Inspiring
September 2, 2008
Question

Referencing one of a series of child clips

  • September 2, 2008
  • 5 replies
  • 448 views
Here's an example of a series of MovieClips being loaded into a container clip:

for(var i:int=0;i<10;i++){
var dotClip:Dot = new Dot();
dotClip.y = i*dotClip.height + 5;
holder1.addChild(dotClip);
}


In attempting to affect one particular loaded clip, I've got this:

var dots:Array = new Array();
for(var i:int=0;i<10;i++){
var dotClip:Dot = new Dot();
dotClip.y = i*dotClip.height + 5;
holder1.addChild(dotClip);
dots.push(dotClip);
}
dots[5].x = -25;

My question is, is there a way to refer to that sixth dot without having to create an array and push all the dots into it? I'm trying to migrate from the AS2 attachMovie() . Many thanks!
This topic has been closed for replies.

5 replies

kglad
Community Expert
Community Expert
September 2, 2008
that won't work if holder1 has other children or will have other children.
Participating Frequently
September 2, 2008
The DisplayList already creates the array for you. You can get a reference from holder1.getChildAt(5)

getChildAt() is faster than getChildByName().
kglad
Community Expert
Community Expert
September 2, 2008
you're welcome.
bhnhAuthor
Inspiring
September 2, 2008
Aha! Thank you, kglad.
kglad
Community Expert
Community Expert
September 2, 2008
yes, you could give them different names instead of all dotClip but it's easier to give them different name properties and use getChildByName() when you latter need to reference a particular Dot instance.