Skip to main content
Inspiring
September 19, 2019
Question

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

  • September 19, 2019
  • 2 replies
  • 316 views

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.

    This topic has been closed for replies.

    2 replies

    kglad
    Community Expert
    Community Expert
    September 19, 2019
    use:
    
    function addToTopF(_parent:DisplayObjectContainer,_child:DisplayObject):void{
    _parent.addChildAt(_child,_parent.numChildren);
    }
    JoãoCésar17023019
    Community Expert
    Community Expert
    September 19, 2019

    Hi.

     

    Can you show us your code?

     

    Regards,

    JC

    Inspiring
    September 20, 2019

    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.