Help optimizing bitmapdata code

Hello all,
I’m not gonna lie, when it comes to BitmapData I have not used it enough to be efficient with it and now I’ve run into an issue I don’t really know how to work myself out of. I don’t even necessarily know that this is the culprit of my problems but I think it is and would like to ask if someone could help me out in optimizing this code (or even a better way to write it).

public function doEraseOnCanvas():void
			var ci:CanvasItem;
			var offset:Point;
			var m:Matrix;
			var items:Array = this._model.timeline.canvas_mc.transformManager.items;
			for (var i:int = 0; i < items.length; i++)
				ci = CanvasItem(TransformItem(items*).targetObject);
				offset = ci.getOffset();
				m = new Matrix();
				m.tx = ci.mouseX - offset.x - this._newSize;
				m.ty = ci.mouseY - offset.y - this._newSize;
				m.a /= this._model.zoom;
				m.d /= this._model.zoom;
				ci.mask_bmd.draw(this._eraser_bmd, m, this._ct, BlendMode.MULTIPLY, null, true);
				ci.photo_bmd.copyChannel(ci.mask_bmd, ci.mask_bmd.rect, this._zeroPoint, 2, 8);
				ci.threshold_bmd.copyChannel(ci.mask_bmd, ci.mask_bmd.rect, this._zeroPoint, 2, 8);

Basically, i’ve got a bunch of items on the stage that have been rotated, scaled, moved (either or none of these options, could be one, could be all, could be none). I loop through them and each item is a CanvasItem type. This part of the code is the “eraser” of the canvas so when i move the mouse, this method is run and erases the item(s) currently underneath it.

The method works and does exactly what it should except that it runs a bit poorly. When I move the mouse quickly the erasing doesnt “catch up” with where the mouse currently is and i suspect it has to do with the drawing for the mask bmd or the copying of channels to the other two bmds that need to have the alpha applied to them.

i don’t really know of any other way to do this or how to speed this up so any help would be GREATLY appreciated.

  • Matt