文王武帅

TextFormat类

  

使用TextFormat()构造函数创建一个具有指定属性的 TextFormat 对象。 然后可更改 TextFormat 对象的属性以更改文本字段的格式设置。

任何参数都可设置为 null 以指示该参数未定义。 所有参数都是可选的;任何省略的参数都被视为 null。下面是一个例子,建立一个文本label,通过TextFormat()写的样式改变label的样式;

 

package {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;


    public class TextFormatExample extends Sprite {
        private var label:TextField;

        public function TextFormatExample() {
            configureLabel();
            setLabel("Hello World and welcome to the show");
        }

        public function setLabel(str:String):void {
            label.text = str;
        }

        private function configureLabel():void {
            label = new TextField();
            label.autoSize = TextFieldAutoSize.LEFT;
            label.background = true;
            label.border = true;

            var format:TextFormat = new TextFormat();
            format.font = "Verdana";
            format.color = 0xFF0000;
            format.size = 10;
            format.underline = true;

            label.defaultTextFormat = format;
            addChild(label);
        }
    }
}

posted on 2012-10-11 23:34  文王武帅  阅读(494)  评论(0)    收藏  举报

导航