inicio
home / inicio

Bitmapdata erasing in as3 (with custom brush shape)

For a drawing program made in flash, i came across the need to erase a bitmapData object using a custom brush tip. Finally i came across this example which was exactly what i needed, except it was written for actionscript 2.

I updated the script to actionscript 3, and added some extra comments that made me understand how this worked. I hope it saves you some time if you need to do something similar. (Please forgive the roughness of the code, its just a test for learning porpouses)

type="application/x-shockwave-flash">

Download erasetest.fla (552 kb)

Gravatar

Bob said,

August 1, 2008 @ 12:41 am

dude, nice! you just saved me a huge headache and tons of time… thanks :)

clean code too

Gravatar

mitomane said,

April 16, 2009 @ 5:18 am

Hi, thanks for the great code example!

I’m using your code to erase part of a BitmapData and I’m rotating this BitmapData using matrix and the erase part work great… but there’s a problem.

I’m rotating an object around the center of a given Point and this is the code of the function I’m using:

public function rotateAroundPoint(m:Matrix, x:Number, y:Number, angleDegrees:Number):void
{
m.translate(-x, -y);
m.rotate(angleDegrees*(Math.PI/180));
m.translate(x, y);
}

Theproblem is that the erasing part is not taking in account the rotation matrix of the BitmpaData and erase part of the image like the image was never rotated at all…

Do you have any idea or suggestion?

Thanks

Gravatar

mitomane said,

April 16, 2009 @ 5:19 am

…”I’m rotating an object around a given Point”

Gravatar

mitomane said,

April 16, 2009 @ 6:52 am

ok more or less I’m near the solution…
when I’ll have everything working good I’ll post the solution.

:-D

Gravatar

mitomane said,

May 6, 2009 @ 5:59 am

Erasing portion of a rotating BitmapData using AS 3
http://www.mitomane.com/?p=128

Gravatar

Frank said,

September 3, 2009 @ 8:41 pm

HELP! Great erase thing you got here. But how can I change the cursor to a big brush and have only the tip erase, not the wooden stick part. I tried:

Mouse.hide();
cursor_mc.startDrag(“true”);

and added another shape to it. With your brush you can still see the mouse pointer and the created brush behind it. I want to replace the mouse pointer with a big brush that layers on top of your brush. So it looks like I have a huge brush but only the tip erases stuff. Any ideas? That would be so great if you could help!

Gravatar

Jean-François Desgagné said,

January 21, 2010 @ 2:56 pm

A copy from http://www.senocular.com/flash/source/?id=0.175 (same comment) 2 years before!

Gravatar

Jean-François Desgagné said,

January 21, 2010 @ 3:09 pm

nvm, written in the script :) Good work

RSS feed for comments on this post · TrackBack URI

Leave a Comment