PDA

View Full Version : swapdepths dynamically in as3



pvsamy
March 14th, 2009, 04:18 AM
hi gurus..

i am new to this forum,
I am doing a drag and drop activity in as3. Since the space is a constraint, I need to swap the dragging object into top depth and the same should go to the bottom most depth after dropped in to correct target, so that the other draggable object won't be hidden behind that. I used swapChildren() method but the problem is: the swapped object comes to the top level while swapping other objects. is there any method to swap the child to a unique depth? (like swapDepths(1000) in as 2.0). please note that all the movieclip objects are being added to the stage dynamically (including dragbar and dropbar).
can any one help me to sort out this issue?

Joony5
March 14th, 2009, 06:31 AM
The method you're looking for is setChildIndex(). You would do something like this:


container.setChildIndex(lozenge, container.numChildren-1);

and then when it's in the right place:


container.setChildIndex(lozenge, 0);

The "lozenge" being the Display Object you want to drag around, and the "container" being the Display Object you added your lozenges to.
If you're doing this with mouse events then you can probably replace "lozenge" with the mouse event's .target property (it's inherited from the Event class).

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/DisplayObjectContainer.html#setChildIndex()

If you click the "show inherited properties" you will be able to see the "target" and "currentTarget" properties and see what they do.
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/events/MouseEvent.html#propertySummary

Bookmark this:
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/

pvsamy
March 16th, 2009, 05:49 AM
thanks guru...

i solved this issue with your help.. thanks a lot.