views:

146

answers:

2

Is there a ActionScript-version of JavaScript's Canvas.clearRect()?

I only know graphics.drawRect(...) which allows me draw but not remove rectangles.

If there is no such method in ActionScript, how can I emulate it?

A: 

graphics.clear();

mwilcox
That won't help because graphics.clear() deletes the whole canvas. What I was asking for was a method to remove one specific rectangle from the canvas.
drawRect is creating bitmap data, not display objects. So if you draw two rectangles, you have a canvas full of pixels. You can't "remove" one of them, short of redrawing over that section or using multiple Sprites as Mike Chambers said.
mwilcox
It's interesting then that removing specific pixels on a HTML5 canvas is possible (through JavaScript)
I agree (commented above too). You probably have to use a mask to do what you want to do.
mwilcox
A: 

There is not an equivalent in ActionScript to clearRect. If you need to do that, then you may want to have multiple sprites, and draw to them separately. That would allow you to adjust z-order, and to remove sections.

If you need to cut out a section of a shape, then you can use drawPath.

mike

mikechambers
Mike, I concur with user286149. I see no easy way to do this. I think drawPath will make donuts, but not punch a hole in an existing bitmap, true? Perhaps there could be a special "color" that deletes pixels.
mwilcox