# For Each...in and displayObjects

**URL:** <https://forum.kirupa.com/t/for-each-in-and-displayobjects/317589>\
**Category:** flash\
**Created:** [December 26, 2010, 9:58am UTC](https://forum.kirupa.com/t/for-each-in-and-displayobjects/317589 "2010-12-26T09:58:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zwaf](https://avatars.discourse-cdn.com/v4/letter/z/e495f1/32.png) [@Zwaf](https://forum.kirupa.com/u/Zwaf)\
**Post date:** [December 26, 2010, 9:58am UTC](https://forum.kirupa.com/t/for-each-in-and-displayobjects/317589/1 "2010-12-26T09:58:59Z")

</div>

Hey Guys,

First of all, a merry Christmas to you all. Better hope its not as snowy at your place as it is at mine. Can’t even get my front door to open.

Anyways, I have been referring to the sticky topic of “AS3: Tip of the Day” for more times than I can count in the past, yet I have a question regarding one of the things discussed in there.

When dealing with the For-Each loop, the example is given of getting all values within an Array. I want to use the For-Each loop for a dynamically created Sprite but it does not work.  
This is the code:

```auto

var thumbnails = new Sprite();
addChild(thumbnails);

for(var i=1;	i<= A_XML.assignment.length();	i++)
{
	var newThumbnail:IndexThumbnail = new IndexThumbnail(...);
thumbnails.addChild(newThumbnail);
}

for each(var child:IndexThumbnail in thumbnails)
{
	trace(child)
}

```

I don’t want to use for(var i=0;i\<thumbnails.numChildren;i++) because the index might be messed up (no child at index0 but instead at 2) because I remove some and I think for each would be a more elegant solution to approach this.

Thanks in advance!
