Depth related problem for actionscript 3 [duplicate]
I'm having trouble managing the depths of my movie clips.
I've got a startDrag()
function and a stopDrag()
function.
Whenever I rollover another MC, I want the depth of that object to change to 1+ the object it rolled over.(I apologize if my English is poor)
Can anyone give me a nudge in the right direction?
EDIT: This is as far as I got, but cIndex returns the depth of the object that is currently being dragged; not the object it's hovering over... Is there a way to get that depth?
mc.addEventListener(MouseEvent.MOUSE_OVER, objectFront);
function objectFront(e:Event):void{
cIndex_t3 = getChildIndex(DisplayObject(e.currentTarget))
trace("ROLLOBJ: " + e.target.name + " " + cIndex_t3);
addChild(DisplayObject(e.currentTarget));
}
If you actually want to object to be +1 the object it rolled over then use getChildIndex() on the object dragged over and use setChildIndex() on the dragged object.
However if you simply want the dragged object on top then the easiest way is to simply use addChild() on it. You can use addChild() even if the object is already a child, and that'll bump it to the top of the stack.
You should use getChildIndex and setChildIndex for depth related operations of display objects.
mc.addEventListener(MouseEvent.MOUSE_OVER, objectFront);
function objectFront(e:Event):void
{
//Set display object child index on top in container
e.target.parent.setChildIndex(e.target as MovieClip, e.target.parent.numChildren - 1);
}
精彩评论