PDA

View Full Version : Change MovieClip Depth on drag



waverider303
March 10th, 2009, 03:14 PM
Is there a way to change the depth (index number) of a movieClip when I click on it to drag. Example:

Say I have three circles. Each circle has a MOUSE_UP and MOUSE_DOWN eventListener. When one is clicked It will bring it to the front so when I drag it will be above the two other circles.

irrationalistic
March 10th, 2009, 03:29 PM
Yeah, when you click on, say, movieclip1, do:


//assuming movieclip1 resides on the stage...
stage.swapDepths(movieclip1, stage.numChildren - 1);

waverider303
March 10th, 2009, 03:40 PM
hmm it does not seem to work. Will i have to place the movieclips on the stage with script?

irrationalistic
March 10th, 2009, 03:49 PM
Where do the movieclips reside? A more surefire but ugly way to do this is:


movieclip1.parent.swapDepths(movieclip1, movieclip1.parent.numChildren - 1);

waverider303
March 10th, 2009, 03:57 PM
is swapDepths supported in AS3? I get an error saying its not

waverider303
March 10th, 2009, 04:00 PM
Here is my file FYI

http://rapidshare.com/files/207668168/dragDepth.fla.html

dail
March 10th, 2009, 04:06 PM
SwapDepths is AS2, as this is an AS3 forum, I guess you want an AS3 method, setChildIndex();

parentDisplayObjectContainer.setChildIndex(yourObj ectClickedOn, parentDisplayObjectContaine.numChildren - 1)

or, this.setChildIndex(event.target as MovieClip, this.numChildren - 1);

irrationalistic
March 10th, 2009, 04:09 PM
Ah that's my bad. Serves me right for not double checking!