[AS3 SNIPPET] Resize movieclip/image (any DisplayObject) to fill specified area

1
2
3
4
5
6
7
8
9
10
11
public static function resizeToFill(mc : *, maxW : Number, maxH : Number = 0, constrainProportions : Boolean = true) : void
{
    maxH = maxH == 0 ? maxW : maxH;
    mc.width = maxW;
    mc.height = maxH;

    if (constrainProportions)
    {
        mc.scaleX > mc.scaleY ? mc.scaleY = mc.scaleX : mc.scaleX = mc.scaleY;
    }
}