0
votes

I have an object and for some reason I want to bring it to front when it starts dragging:

  myObject.startDrag();
  setChildIndex(myObject, numChildren-1);

Now, when I go to next or previous frame, myObject is over other objects. How I can restore the myObjects index to default value at the begining, after dargged it?

2

2 Answers

1
votes

before calling

 startDrag()

use

 var previousIndex = getChildIndex(myObject);

after dragging is finished then set the index of object to previous object.

 setChildIndex(myObject, previousIndex);

I hope this would help.

0
votes

First store default object index. Suppose myBox is your display object. Now you can set default index of object when you want.

var originalIndex = this.getChildIndex(myBox);

myBox.addEventListener(MouseEvent.MOUSE_DOWN,onDown);
myBox.addEventListener(MouseEvent.MOUSE_UP,onUp);

function onDown(e:MouseEvent)
{
     //Set object index on top
     this.setChildIndex(myBox,this.numChildnre-1);
     myBox.startDrag();
}

function onUp(e:MouseEvent)
{
     myBox.stopDrag();

     //Set object index as originalIndex
     this.setChildIndex(myBox,originalIndex);
}