[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;
    }
}

[AS3 SNIPPET] Set links style of specified TextField using CSS

1
2
3
4
5
6
7
8
9
public static function setLinksStyle(tf : TextField, linkColor : Number = 0x000000, linkHoverColor : Number = 0x666666, underline : Boolean = true) : void
{
var _underline : String = underline ? "underline" : "none";

var ss : StyleSheet = new StyleSheet();
ss.parseCSS("a:link {color: " + ColorUtil.hex2css(linkColor) + "; text-decoration: " + _underline + ";}" + "a:hover {color: " + ColorUtil.hex2css(linkHoverColor) + "; text-decoration: " + _underline + ";}");

 tf.styleSheet = ss;
}

You can find the ColorUtil class here.