Z order can be controlled via setChildIndex(child,index) and swapChildrenAt(index,index), which are in the DisplayObjectContainer class. 0 is the bottom and the numChildren-1 would be the top.
Example (code here would be in the container of anObject):
setChildIndex(anObject,numChildren - 1); sets anObject to be on top.
In my game engine, I stored all of the objects that would be drawn in an array. I then had all of the objects that would be drawn contain a property called depth. Then I sorted the array and repeated the above line to order it according to the depth variable.
ActionScript Code:
//sorts the array based on the variable "depth" in each object
containsArray=containsArray.sortOn("depth",Array.NUMERIC);
//orders the child array inbuilt into Flash to whatever we want
for each(var obj in containsArray)
{
if(contains(obj))
{
setChildIndex(obj ,numChildren - 1);
}
}
---
As for removal of objects, Flash handles most of it quite nicely after you call remove it from its container. The only thing it won't do is remove all of the event listeners (yes, stupid, I know) and remove itself from any arrays you may have had it in, which matters if you do the above solution to z-ordering. graphics.clear() and setting pathShape and pathPoints to null isn't necessary.