# setChildIndex on a for loop

**URL:** <https://forum.kirupa.com/t/setchildindex-on-a-for-loop/295375>\
**Category:** flash\
**Created:** [August 28, 2009, 7:32pm UTC](https://forum.kirupa.com/t/setchildindex-on-a-for-loop/295375 "2009-08-28T19:32:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![aa72](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@aa72](https://forum.kirupa.com/u/aa72)\
**Post date:** [August 28, 2009, 7:32pm UTC](https://forum.kirupa.com/t/setchildindex-on-a-for-loop/295375/1 "2009-08-28T19:32:40Z")

</div>

What I have is an array of 3 pictures closely in a column, that expand on a MOUSE\_OVER. I want the object to be in front of the others on the MOUSE\_OVER, but part of it is always beneath.

```auto
var thumbnails:Array = ["IMG_1258.JPG","IMG_1417.JPG","IMG_1428.JPG"];
var studioGallery:MovieClip = new MovieClip();
addChild(studioGallery);

for(var i:int = 0; i < thumbnails.length; i++){
    var img:Loader = new Loader();
    img.load(new URLRequest("images/"+thumbnails*));
    img.x = 100;
    img.y = 10 + i * 100;
    img.alpha = 0;
    img.scaleX = img.scaleY =.5;
    studioGallery.addChild(img);
    img.contentLoaderInfo.addEventListener(Event.COMPLETE, onReady);
    img.addEventListener(MouseEvent.ROLL_OVER, onOver);
    img.addEventListener(MouseEvent.ROLL_OUT, onOut);
    
}
 
function onReady(evt:Event):void {
    var img:Loader = Loader(evt.currentTarget.loader);
    img.content.x = -img.content.width / 2;
    img.content.y = -img.content.height / 2;
    Bitmap(img.content).smoothing = true;
    img.addEventListener(Event.ENTER_FRAME, onFadeIn);
    studioGallery.x = 200;
    studioGallery.y = 200;
    
}
function onFadeIn(evt:Event):void {
    var img:Loader = Loader(evt.currentTarget);
    img.alpha += (1 - img.alpha)/12;

}

function onOver(evt:MouseEvent):void {
    evt.currentTarget.scaleX = evt.currentTarget.scaleY = 2;

}
//
function onOut(evt:MouseEvent):void {
    evt.currentTarget.scaleX = evt.currentTarget.scaleY = .5;
}

```

I tried to add the following line of code on OnOver as I saw it in another thread, but it gives me an error message:

```auto
  this.setChildIndex(this.getChildByName(evt.currentTarget.name), this.numChildren-1);

```

Can somebody be so kind to help me.
