Search code examples
actionscript-3flashz-indexaddchild

how do I keep one movieclip on top of another in actionscript 3


so, let´s say I addChild(mc1); at the beginning of the code, how do I keep it on top of addChild(mc2); when I add more stuff later on in the code? by default mc2 will cover mc1... I have tried z-indexes, but I have not completely grasped how to use it in my situation... help?

thanks!


Solution

  • A couple of suggestions:

    1. Use addChildAt(mc1, 0) addChildAt(mc2, 1). You can use addChildAt to state a specific 'layer' to add a movieclip to.

    2. Whenever you add anything else, re-add the movieclip you want to keep on top, ie:

      addChild(mc1); // adds first mc

      addChild(mc2); // adds second mc on top of first

      addChild(mc1); // re-draws mc1 to the top layer (does not add again, just brings to top!)