for my game it was necessary to correctly arrange all the MovieClips by depth, but there were many problems and so I did not find a solution, and I wrote myself, all that is needed for this is arranging everything along Y, the more Y (the zero coordinate in as3 is on top, which means we have Y going down) the more depth, and vice versa, the less Y the less depth
this code must be made either a module or a MovieClip, if you want to add MovieClips, add them by class, as you can see in the updateDepths() function in if()
package { import flash.display.*; import flash.events.*; public class DepthY extends MovieClip { private var mc:DisplayObject; public function setDepth(obj:DisplayObject):void { var depth:int = Math.floor(obj.y); if (depth < 0) { depth = 0; } else if (depth >= obj.parent.numChildren) { depth = obj.parent.numChildren - 1; } obj.parent.setChildIndex(obj, depth); } public function updateDepths():void { if (parent) { var objects:Array = []; for (var i:int = 0; i < parent.numChildren; i++) { var obj:DisplayObject = parent.getChildAt(i); if ((obj is hitBoxPlayer || obj is asClass || obj is gadjetHit) && obj != this && obj.parent == parent) { objects.push(obj); } } objects.sortOn("y", Array.NUMERIC); for each (var sortedObj:DisplayObject in objects) { setDepth(sortedObj); } } } public function DepthY() { addEventListener(Event.ENTER_FRAME, onEnterFrame); } private function onEnterFrame(event:Event):void { updateDepths(); } } }
this code uses Event.ENTER_FRAME so be careful