Hi guys

Just a quick one regarding z-indexing/child indexing.
I'm in a bit of a problem here!!

Supposing I create a instance of a tree sprite and place it at 250x, 300y.
Then I create 20 instances of a sphere. The spheres randomly move around, infront of and behind the static tree, but everything is indexes itself correctly so things move behind and in front of each other.

I've heard this is called z-indexing, and it needs to be done on every frame update but I'm having a lot of difficulty doing this in AS3. Does anyone have any hints, algorithms/solutions on how to solve this?

Any help would be appreciated.

Thank you!