# Parent and child relationships with swapping depths

**URL:** <https://forum.kirupa.com/t/parent-and-child-relationships-with-swapping-depths/300554>\
**Category:** Uncategorized\
**Created:** [November 23, 2009, 5:19pm UTC](https://forum.kirupa.com/t/parent-and-child-relationships-with-swapping-depths/300554 "2009-11-23T17:19:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![geestring](https://avatars.discourse-cdn.com/v4/letter/g/e19b73/32.png) [@geestring](https://forum.kirupa.com/u/geestring)\
**Post date:** [November 23, 2009, 5:19pm UTC](https://forum.kirupa.com/t/parent-and-child-relationships-with-swapping-depths/300554/1 "2009-11-23T17:19:29Z")

</div>

```auto
function blah(){	
	
	for(var f:int = first; f<last; f++){
		
	
				
	var hold:MovieClip = new MovieClip();
		
	
		addChild(hold);
		mcHolder.addChild(hold);
		
		depthArray.push(hold);
		
		storage[hold]= new Object();
		storage[hold].id = f-first;
		storage[hold].depth = depthArray;
	
		
		
	}
	mcHolder.y = 0;
	mcHolder.x = 100;
	addChild(mcHolder);
	
	
	
}

function hover_on(e:MouseEvent):void{
	var a:Object = storage[e.currentTarget];
	var theId:Number = a.id; //number of the button that is hovered.
	var theDepth:Array= a.depth;
	
	

   for(var c:int = 0; c<theDepth.length; c++){
	   if(mcHolder.getChildAt(theDepth.length-1) == theDepth[c]){
		   var highestDepth:Object = theDepth[c];
   		}
   }
	mcHolder.parent.swapChildren(theDepth[theId], highestDepth); // i guess this is the line I'm having trouble with
}

```

the code is stripped down for the sake of brevity. I’m just trying to show where everything is.

so “hold” is the button and is in a loop. All the buttons are placed in mcHolder.  
How do I swap depths within the mcHolder?
