I have this function within a class that creates a bitmap of any DisplayObject I pass in. As you will see, each time I create a new bitmap I am creating a new BitmapData object and a new Bitmap Object.
Is there a way to tweak this function so I no longer have to recreate these two objects each time I run the function?
private var bitmapData:BitmapData;
private var bm:Bitmap;
crop(someSprite.width, someSprite.height, someSprite);
private function crop(_width:Number, _height:Number, displayObject:DisplayObject):void {
bitmapData.dispose();
bitmapData = new BitmapData( _width, _height, false, 0xFFFFFFFF );
bitmapData.draw(displayObject);
bm = null;
bm = new Bitmap(bitmapData, PixelSnapping.ALWAYS, true);
bm.smoothing = true;
bm.alpha = 0;
}
Thanks,
Mark