# setChildAt errors and troubles

**URL:** <https://forum.kirupa.com/t/setchildat-errors-and-troubles/257692>\
**Category:** flash\
**Created:** [April 16, 2008, 12:08pm UTC](https://forum.kirupa.com/t/setchildat-errors-and-troubles/257692 "2008-04-16T12:08:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![thatguythatsme](https://avatars.discourse-cdn.com/v4/letter/t/c0e974/32.png) [@thatguythatsme](https://forum.kirupa.com/u/thatguythatsme)\
**Post date:** [April 16, 2008, 12:08pm UTC](https://forum.kirupa.com/t/setchildat-errors-and-troubles/257692/1 "2008-04-16T12:08:52Z")

</div>

Hello all,

I’m trying to make a simple gallery with over lapping images, when clicked I trying to make the selected image change its index value to come to the front. I seem to be hitting a brick wall with ArgumentErrors and RangeErrors…

This is my code

```auto

private function xmlLoadedHandler(event:Event):void 
        {
            _xmlObject = new XML(event.target.data);
            
            addChild(container);
            var i:uint = 0;
            for each(var image:XML in _xmlObject.image)
            {
                i = i + 1;
                var displayImage:ImageDisplay = new ImageDisplay(_xmlPath + image.@src);
                container.addChildAt(displayImage, 0);
                displayImage.name = "image" + i;
                trace(displayImage.name);
                displayImage.x = image.@x;
                displayImage.y = image.@y;
                displayImage.alpha = 0.5;
                displayImage.rotation = Math.random() * 15;
                displayImage.addEventListener(MouseEvent.CLICK, onMouseEventHandler);
            }
            trace("There are", container.numChildren, "images in this gallery!");
        }
        
        private function onMouseEventHandler(event:MouseEvent):void
        {
            event.target.setChildIndex(event.target, container.numChildren - 1);
            
            //var circle:Sprite = Sprite(event.target);
            //var topPosition:uint = container.numChildren - 1;
            //container.setChildIndex(circle, topPosition);
            
            //container.setChildIndex(container.getChildAt(1), 0);
        }

```

I’ve tried a few different ways in the onMouseEventHandler function but so far turned up nothing.

Any help would be appreciated.

Dave
