Question

Right, so here's the scenario: I have 4 objects, A, B, C and D. What I want is that C obscures A, but not B. Similarly, I want D to obscure B, but not A. A and B can overlap each other in any order, it doesn't matter.

In other words, what I want is an object (C) to be able to cover one object (A) but not another (B), even if it comes into contact with it. Same with D, which can cover B but not A, even if it comes into contact with it. The problem is that I can't think of a layer configuration that allows this: D will always be higher than both A and B, and thus will obscure both.

I'm not expecting anyone to come up with some unfathomably clever configuration, but I'm wondering if there's some kind of ActionScript that can do this. In particular, I would like A and B to be dynamic TextFields, and C and D to be MovieClips of any shape (i.e. not a rectangle).

Hope this is possible!

Was it helpful?

Solution

You could use blitting, where you're not actually adding the items to the stage, but instead are using copyPixels() or draw() to draw the pixels. If you did this, then you could determine what parts of the objects would or would not be drawn. Check out this blog post for an overview of the technique http://www.developria.com/2010/02/dealing-with-bitmapdata.html.

OTHER TIPS

The order in which you add them to the stage determines what shows up in front of what. Basically, whatever is added last is on top, whatever is added first is on the bottom.

If you want C to cover A but not B and D to cover B but not A, you have a problem. Think about what would happen if all four were overlapping each other. C would be trying to cover A and let B show through, while D would be trying to cover B and let A show through. Not possible.

Assuming I understood what you want, use the setChildIndex() function of the parent/containing MovieClip. If all of your ABCD objects were contained in a MovieClip named parent_mc, you can do something like:

parent_mc.setChildIndex(a_mc, parent_mc.numChildren-1); // Throw "a_mc" on top
parent_mc.setChildIndex(b_mc, parent_mc.numChildren-1); // Throw "b_mc" on top

This wouold result in b_mc being on top of a_mc, etc...

You chould also throw something on the very bottom of the display list:

 parent_mc.setChildIndex(b_mc, 0);

documentation here: DisplayObjectContainer.setChildIndex()

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top