Hey i'm trying to erase a movieclip but it doesnt want to work. My code is:
private function setupErase():void{
var toolsize = 20;// size used for tools (width = height)
var tooloffset = toolsize/2;//
var bitmap:Bitmap=new Bitmap();
var bd:BitmapData=new BitmapData(filth.width,filth.height,true,0x00FFFFFF);
var basepoint = new flash.geom.Point(0, 0);
bd.draw(filth);
bitmap.bitmapData=bd;
addChild(bitmap);
bitmap.x = filth.x;
bitmap.y = filth.y;
removeChild(filth);
var erasebmp:BitmapData = new BitmapData(toolsize, toolsize, true, 0xFFFFFFFF);
var rect:Rectangle=new Rectangle(erasebmp.width,erasebmp.height);
// then draw the shape (black) into the bitmap
erasebmp.draw(sponge);
// copyChannel is used to convert the shape of the tool
// just added (drawn) into erasebmp into it's alpha channel
erasebmp.copyChannel(erasebmp, erasebmp.getColorBoundsRect(0xFFFFFF,0,true), basepoint, 1, 8);
var pointer_mc:MovieClip=new MovieClip();
pointer_mc.addChild(sponge)
sponge.x=-sponge.width/2
sponge.y=-sponge.height/2
addChild(pointer_mc);
//listeners
stage.addEventListener(MouseEvent.MOUSE_MOVE,onMove);
stage.addEventListener(MouseEvent.MOUSE_DOWN,onDown);
stage.addEventListener(MouseEvent.MOUSE_UP,onUp);
var erasing:Boolean=false;
function onDown(ev:MouseEvent) {
erasing=true;
erase();
}
function onUp(ev:MouseEvent) {
erasing=false;
}
function onMove(ev:MouseEvent) {
pointer_mc.x=mouseX;
pointer_mc.y=mouseY;
if (erasing) {
erase();
}
}
function erase() {
// devise an offset based on the mouse's
// position in pointer_mc and tooloffset
var offset = new flash.geom.Point(mouseX-(pointer_mc.width/2) , mouseY-(pointer_mc.width/2) );
// devise a drawing rectangle the size of the
// the drawing tools at the offset's location
var drawRect = new flash.geom.Rectangle(offset.x, offset.y, toolsize, toolsize);
// next, copy pixels from the drawbmp back onto itself
// (makes for no change) but use erasebmp as the alphaBitmap
// this will add the alpha channel information from erasebmp
// into drawbmp erasing pixels from drawbmp in the shape of erasebmp
bd.copyPixels(bd, drawRect, offset, erasebmp, basepoint, false);
}
}
"filth" is what needs to be erased and "sponge" is what needs to erase it. Anyone see where the problem is?