Skip to main content
Participant
July 26, 2018
Answered

How to chose which layer is on top in seperate timelines?

  • July 26, 2018
  • 2 replies
  • 345 views

Hello, I am creating a drag and drop game and I have all of the elements of the 'outfit' set up, however one layer which would need to be on top of all the others is hidden behind one  (for example, the stitch later is hidden behind the fabric layer in one section' how can i make the stich timeline the top layer?

Thank you

This topic has been closed for replies.
Correct answer JoãoCésar17023019

In your onGarmentClick function body, you could add a statement like this:

(event.currentTarget.parent as MovieClip).setChildIndex(event.currentTarget, (event.currentTarget.parent as MovieClip).numChildren - 1);

Alternatively, you can write:

(event.currentTarget.parent as MovieClip).addChild(event.currentTarget); // addChild always adds the object to the top

Please see if one of these works.

And if you need further reference for drag and drop games, please check this thread:

Animate Drag/Drop Help

2 replies

Legend
July 26, 2018

amyo53096887  wrote

Hello, I am creating a drag and drop game and I have all of the elements of the 'outfit' set up, however one layer which would need to be on top of all the others is hidden behind one  (for example, the stitch later is hidden behind the fabric layer in one section' how can i make the stich timeline the top layer?

Click the layer name on the left of the timeline view and drag it to the top.

JoãoCésar17023019
Community Expert
Community Expert
July 26, 2018

Hi. You can achieve this by using the setChildIndex method for both AS3 and JavaScript. Like this:

AS3

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

JavaScript

this.container.setChildIndex(child, this.container.children.length - 1);

* 'container' and 'child' are generic names. Replace with yours.

I hope this helps.

Regards,

JC

Participant
July 26, 2018

Hello,

Thank you for the quick responce, im quite new to animate so still a little confussed to what I would replace 'child' and 'container' with to make this work for my game. This is the code I am using for the section which I wish to be the top layer, hopefully this makes sense?

var myGarmentArray = [pinkstitch, bluestitch, greenstitch, purplestitch, purplecrossstitch, pinkcrossstitch, bluecrossstitch, greencrossstitch];

for each (var garment in myGarmentArray) {

    garment.addEventListener (MouseEvent.CLICK, onGarmentClick);

garment.buttonMode = true;

}

function onGarmentClick (event:MouseEvent):void {

    MovieClip(parent).logo_mc.gotoAndStop (event.target.name);

}

Thanks,

Amy

JoãoCésar17023019
Community Expert
JoãoCésar17023019Community ExpertCorrect answer
Community Expert
July 26, 2018

In your onGarmentClick function body, you could add a statement like this:

(event.currentTarget.parent as MovieClip).setChildIndex(event.currentTarget, (event.currentTarget.parent as MovieClip).numChildren - 1);

Alternatively, you can write:

(event.currentTarget.parent as MovieClip).addChild(event.currentTarget); // addChild always adds the object to the top

Please see if one of these works.

And if you need further reference for drag and drop games, please check this thread:

Animate Drag/Drop Help