Depth management beyond me.. [AS3]

Hello,

I’m having some trouble getting around this little depth thing of mine… Anyway, please look at the picture I attached, now, there is a number on each planet… Quite obviously the depth… But I’ll refer to the planets by their number.

So, imagine planet 1 is behind planet 0, this could be handled by just switching their index, but… As planet 2 is in a orbit around planet 1, it would have to be switched as well, same would apply when they emerge again…

I’ve got no idea how I should approach this :crying:

Any help would be appreciated, thank you.

Note that the ‘real thing’ contains way more than 3 planets