# Reference to addchild in a for loop

**URL:** <https://forum.kirupa.com/t/reference-to-addchild-in-a-for-loop/235492>\
**Category:** Uncategorized\
**Created:** [August 11, 2007, 9:17pm UTC](https://forum.kirupa.com/t/reference-to-addchild-in-a-for-loop/235492 "2007-08-11T21:17:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![vintage](https://avatars.discourse-cdn.com/v4/letter/v/e68b1a/32.png) [@vintage](https://forum.kirupa.com/u/vintage)\
**Post date:** [August 11, 2007, 9:17pm UTC](https://forum.kirupa.com/t/reference-to-addchild-in-a-for-loop/235492/1 "2007-08-11T21:17:45Z")

</div>

pfff…my 3th question about as3 in 2 days…embaressed…

I “attach” movieclips from the library, but I want them to do something when I click something else…

everything works perfect (beside the error you get if you try my code), I just dont know how to refer back to “the other” movieclips…

You have to believe me if I say I tried a zillion different ways…pls tell me how…(did this sounded desperate ? 😃 )

```auto
var ammount:Number = 6;

function make():void {
    //make thumbs
    for (var i:Number = 0; i<ammount; i++) {
        var k:Thumb = new Thumb();//clip in lib with classname Thumb
        k.x = i*20;
        k.y = 75;
        k.name = "Thumb"+i;
        addChild(k);
    }
    loadImg(0);
}
make();

function loadImg(pad:int) {
    for (var z:Number=0; z<ammount; z++) {

        //here Im stuck .... :(
        if (z==pad) {
            getChildByName("Thumb" + z).gotoAndStop(2);//how on earth can I refer to this mc ?
        } else {
            getChildByName("Thumb" + z).gotoAndStop(1);//how on earth can I refer to these mc's ?
        }
    }
}

```

thx in advance from a guy that dives into his bottle without problems (whiskey ^^ )
