views:

288

answers:

2

If you try the following code:

g.beginFill(0xFF0000);
g.drawRect(0, 0, 50, 50);
g.drawRect(25, 25, 50, 50);
g.endFill();

You would think that it would draw 2 overlapping red squares. However, it doesn't - it draws two red squares except for the overlapping area which is now completely transparent.

Any idea how to get around this?

Post-Accepted-Answer:

Thanks Christophe Herreman! Changing the code to:

g.beginFill(0xFF0000);
g.drawRect(0, 0, 50, 50);
g.endFill();
g.beginFill(0xFF0000);
g.drawRect(25, 25, 50, 50);
g.endFill();

Worked just as intended! I'd be interested to know if this was "intended behaviour" or an actual bug though!

A: 

Wouldn't you need to create a second graphic object to apply the second fill to? I bet you really have one strangely shaped graphic object instead of two intersecting rectangles.

anopres
+3  A: 

All calls prior to endFill() will just store the points of the polygon you want to draw and connect them once endFill() is called. Since the code in your example has an overlapping part, it will be filtered out when the actual lines of the polygon are drawn. I actually don't know if this is intended behavior of the Flash player or a bug.

To solve this, just add a new call to beginFill() before drawing the new rectangle.

g.beginFill(0xFF0000);
g.drawRect(0, 0, 50, 50);
g.beginFill(0xFF0000);
g.drawRect(25, 25, 50, 50);
g.endFill();
Christophe Herreman