Quick reference: Drawing a scaled object in Actionscript

Just as a quick reference, since I usually forgot each time how to do it.

Assume to have a DisplayObject obj, you want to draw in a Bitmap a scaled snapshot of that object.

Just like when you are drawing thumbs.

public function drawScaled(obj:DisplayObject, thumbWidth:Number, thumbHeight:Number):Bitmap {
var m:Matrix = new Matrix();
m.scale(thumbWidth / obj.width, thumbHeight / obj.height);
var bmp:BitmapData = new BitmapData(thumbWidth, thumbHeight, false);
bmp.draw(obj, m);
return new Bitmap(bmp);
}

Do you want to leave a comment?