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

How to Make addChildAt Add MC to the Top of Depth?

Explorer ,
Sep 18, 2019 Sep 18, 2019

When I use addChildAt, it adds the MC to the bottom of the list of the depth I specify. Is there a way to make this do the opposite? As in, make it so that it adds the MC above the depth of all the MC's in the depth specified? Thank you.

299
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
Community Expert ,
Sep 19, 2019 Sep 19, 2019

Hi.

 

Can you show us your code?

 

Regards,

JC

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
Explorer ,
Sep 19, 2019 Sep 19, 2019
LATEST

Sure thing:

 

var grunt:Grunt = new Grunt;
addChildAt(grunt,under_hud);

 

"under_hud" refers to directly underneath the game's HUD, which I have in a seperate code in an attempt to manage the depth, right here:

 

setChildIndex(cursor, numChildren -1);
under_cursor = getChildIndex(cursor) - 1;
setChildIndex(pause_screen, getChildIndex(cursor) -1);
setChildIndex(hud, getChildIndex(pause_screen) -1);
under_hud = getChildIndex(hud) - 1;

 

 So what this is supposed to do is set the game's cursor to be the top MC at all times, and then below that is the pause screen when the pause button is pressed, and below that is the HUD.

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
Community Expert ,
Sep 19, 2019 Sep 19, 2019
use:

function addToTopF(_parent:DisplayObjectContainer,_child:DisplayObject):void{
_parent.addChildAt(_child,_parent.numChildren);
}
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