var MaxDepth=100; for(var i in arr){ mc=arr[i]; mc.defaultDepth=i; mc.swapDepths(i); mc.onRollOver=function(){ this.swapDepths(MaxDepth); } mc.onRollOut=function(){ this.swapDepths(this.defaultDepth); } }