mcs = [a_mc, b_mc, c_mc]; mc_swap = Number.MIN_VALUE; // for (var i in mcs) { mc_swap = Math.max(mc_swap, mcs[i].getDepth()); mcs[i].onPress = function() { this.swapDepths(mc_swap); this.startDrag(); }; mcs[i].onRelease = stopDrag; }