# Swap Depth not Working

**URL:** <https://forum.kirupa.com/t/swap-depth-not-working/286947>\
**Category:** flash\
**Created:** [April 23, 2009, 10:02am UTC](https://forum.kirupa.com/t/swap-depth-not-working/286947 "2009-04-23T10:02:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![clubzero](https://avatars.discourse-cdn.com/v4/letter/c/ed655f/32.png) [@clubzero](https://forum.kirupa.com/u/clubzero)\
**Post date:** [April 23, 2009, 10:02am UTC](https://forum.kirupa.com/t/swap-depth-not-working/286947/1 "2009-04-23T10:02:16Z")

</div>

I’ve finally decided to dive into AS 3.0, coming from a design background, It’s been a struggle. I’m using the book “Learning AS 3.0 - A Beginners’s Guide” and got stuck on Chapter 4 - Depth Management. Hope someone can salvage this poor soul …

Ok, here’s my problem, I have dynamically layout layout 5 boxes that overlap each other, after that, Im able to target each box with my Event Listener (evt.target.alpha -= 0.2), but I’m not able to swap their depths (this.setChildIndex(evt.target, this.numChildren-1)😉

```auto

// Layout Boxes - Dynamically
for(var i:Number=0; i < 5; i++){
 var box:MovieClip = new Box();
 box.y = 100;
 box.x = 100 + i * 50;
 addChild(box);
}
// Swap Depths
this.addEventListener(MouseEvent.MOUSE_OVER, onBringToTop);
function onBringToTop(evt:MouseEvent):void{
 // Does not work
 this.setChildIndex(evt.target, this.numChildren-1);
 // This works
 evt.target.alpha -= 0.2;
trace(evt.target.name);
} 

```

the other thing I don’t understand is, the boxes are also added as level0 \>\> instance\_“X” \>\> instance\_“Y” (see Code Below from Debug \>\> List Objects).

When I use the “trace(evt.target.name);” I get instance\_Y? Shouldn’t I get instance X instead without Y?

```auto

Level #0: Frame=1
  Movie Clip: Frame=1 Target="_level0.instance1"
    Movie Clip: Frame=1 Target="_level0.instance1.instance2"
      Shape:
  Movie Clip: Frame=1 Target="_level0.instance4"
    Movie Clip: Frame=1 Target="_level0.instance4.instance5"
      Shape:
  Movie Clip: Frame=1 Target="_level0.instance7"
    Movie Clip: Frame=1 Target="_level0.instance7.instance8"
      Shape:
  Movie Clip: Frame=1 Target="_level0.instance10"
    Movie Clip: Frame=1 Target="_level0.instance10.instance11"
      Shape:
  Movie Clip: Frame=1 Target="_level0.instance13"
    Movie Clip: Frame=1 Target="_level0.instance13.instance14"
      Shape:

```

Thanks in advance 🙂
