Swap Depth not Working

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):wink:


// 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?


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 :slight_smile: