# For loop addChild()

**URL:** <https://forum.kirupa.com/t/for-loop-addchild/290500>\
**Category:** flash\
**Created:** [June 15, 2009, 10:06pm UTC](https://forum.kirupa.com/t/for-loop-addchild/290500 "2009-06-15T22:06:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![asthyanax](https://avatars.discourse-cdn.com/v4/letter/a/50afbb/32.png) [@asthyanax](https://forum.kirupa.com/u/asthyanax)\
**Post date:** [June 15, 2009, 10:06pm UTC](https://forum.kirupa.com/t/for-loop-addchild/290500/1 "2009-06-15T22:06:05Z")

</div>

Hi,  
I know that everybody asked for that kind of question but I still have problem with it. I’m adding clip to the stage with flvplayback component in it with a for loop. I want to replay each video at the end but it always plays the last one only or if I try to target with childByName i have errors. I’m sure it’s pretty easy but I just can’t figure it out.  
Here’s my code:

```php

            var container:MovieClip = new MovieClip();
            addChild(container);
            var vidPlayer:vid_mc;
            for (var i:Number=0; i<4; i++) {
                vidPlayer=new vid_mc();
                vidPlayer.x=i*(100+space);
                vidPlayer.name="vid"+i;          
                container.addChild(vidPlayer);               
                vidPlayer.vid.source="3897623.flv";
                vidPlayer.y=0;
                vidPlayer.vid.addEventListener("complete",replayVid);
                //replay videos
                function replayVid(e:Event):void {
                    trace("Replaying videos");
                    vidPlayer.vid.seek(0);
                    vidPlayer.vid.play();
                }
            }

```

Thanks for your help.
