views:

122

answers:

2

Are there any AS3 classes to help arrange objects into layers, like in the designer, such that the objects all have the same parent?

Obviously, I can use container clips to simulate layers, but I specifically want this kind of functionality for objects that have the same parent.

My understanding is that the design-time notion of layers does not exist at run-time, and objects just have a depth index.

I'm creating a class to simulate layering functionality with a single parent, but if one already exists, I'd like to check it out.

On a side note... how do design-time layer masks manifest themselves at runtime in AS3? I thought maybe all objects on the masked layer share the same mask object, but the "mask" property appears to be null for all objects on the masked layer, even though they share the same parent timeline as the unmasked objects (i.e. unmasked layer object parent == masked layer object parent; therefore, no masked subcontainers appear to be in use).

A: 

You can change the layer ordering of objects at runtime based on their 'child index'. Basically you use the container.setChildIndex(child, index) method. Any object with a higher index will appear to be on top of any child with a lower index. There are also two convenience functions swapChildren(child1, child2) and swapChildrenAt(index1, index2) for swapping the index of two children in a single call instead of needing to make two.

davr
A: 

One way to implement layers is to make an empty Sprite for each layer, and add the objects you want in each layer to the relevant Sprite as children. Then these "layers" can be sorted in the same way that you sort display objects normally.

danyal
"Obviously, I can use container clips to simulate layers, but I specifically want this kind of functionality for objects that have the same parent."
Triynko
Sorry, I missed that. I'd be interested to see what you come up with. I would probably end up starting by having the children inherit from a new base class, which has a member variable layer:int, and then writing some functionality around that. But you have probably gone some way to mapping out a good solution to this by now.
danyal