Skip to main content
Participant
May 14, 2007
Question

How to get a list of all the child movieclips of a movieclip

  • May 14, 2007
  • 2 replies
  • 403 views
Hi!

I was wondering how I could get a list of all the movieclips inside a given movieclip.

For example, suppose I have two instances of a ball movieclip: ball1 and ball2. These movieclips are inside another one named balls.

Is there any method you could call on the movieclip balls that returns a reference to an array or object that with all the movieclips inside it (in this case ball1 and ball2).

I know I can use balls['ball1'] to reference one of the movieclips, but balls.length or balls[0] does not work.
This topic has been closed for replies.

2 replies

Inspiring
May 14, 2007
Don't forget that it is possible – if your project is built that way – that the children can have children as well. So you can do some kind of recursive function that if _root.clip1 is a typeof movieclip then check inside it too.
Participating Frequently
May 14, 2007
In Actionscript 3 you can just look at the 'numChildren' property of the top movieclip, and use the getChildAt () method to access those children.

In Actionscript 2 you could loop through all the properties of a movieclip to find it's children. Like this:

_root.attachMovie("myClip", "clip1", 10) // attach the top one
_root.clip1.attachMovie("myClip", "clip2", 11) // attach one beneath it

for (var x in _root.clip1) // loop through all the properties of the top clip
{
trace(x + " " + typeof(_root.clip1)) // work out if they are movieclips
}


Nick

Participant
May 14, 2007
That was exactly was I was hoping to find, but was not very well documented.

Thank you!