Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

move clip to top level

Contributor ,
May 14, 2013 May 14, 2013

I've got a movieclip containing another movieclip which acts as a button. The movieclip has a drag function added to it.

function onBoxPress( event:MouseEvent ):void

          {

                    var boundsRect:Rectangle = new Rectangle(event.currentTarget.x,0,0,stage.height);

                    event.currentTarget.startDrag(false, boundsRect);

          }

          //;

          function onBoxRelease( event:MouseEvent ):void

          {

                    event.currentTarget.stopDrag();

                    sortBoxes();

          }

On the stage I've got several copies of this clip. It works ok: when I click and drag, the clip drags vertically. However, each clip has its own depth and sometimes a clip will drag beneath another clip. So upon clicking and dragging the clip should be moved to the top level of all duplicate clips.

How do I move it to the front of all other clips?

I've tried using:

function onBoxPress( event:MouseEvent ):void

          {

                    setChildIndex(event.currentTarget.parent,0)

                    var boundsRect:Rectangle = new Rectangle(event.currentTarget.x,0,0,stage.height);

                    event.currentTarget.startDrag(false, boundsRect);

          }

I use event.currentTarget.parent here because the clip to have it's index set is the parent clip. Remember, the button which starts it all is inside that parent clip.

But then I get an error 2025:

Error #2025: The supplied DisplayObject must be a child of the caller

TOPICS
ActionScript
455
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
May 14, 2013 May 14, 2013
LATEST

The parent is not the child of the child. Call setChildIndex on an object that is the parent of the parent.

The whole reason you're having this problem is because you're violating good Object Oriented Design by having the child manage too much. The grandparent should be listening for the MouseDown and then managing the drag. You could have a single event handller that checks for the MouseDown and checks the Class of the target (set mouseChildren to false on the button, so the target won't be its label, for example.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines