迟到的春天

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

as3.0文本居中显示很费事,不像html那样简单,必须具备3个条件

1、设置文本样式的属性 TextFormat 居中

2、设置文本宽度

3、文本内容必须用text属性而不能用htmlText属性

4、文本宽度 必须在text属性之前设置

实例如下:

package MC.QQMC.QQShare
{
   import flash.text.TextField;
   import flash.text.TextFormat;
   public class OneShareMC extends MovieClip
   {
    private var txtform:TextFormat;
    public function OneShareMC()
    {

     //设置文本居中属性
       txtform=new TextFormat();
       txtform.align="center";

       var numTxt:TextField= new TextField();
       numTxt.textColor=0x00ff00;
       numTxt.defaultTextFormat=txtform;
       numTxt.width=45;//宽度一定要有而且 宽度一定要再 text 赋内容之前

     numTxt.background=true;
       numTxt.backgroundColor=0x121313;
       numTxt.border=true;
       numTxt.borderColor=0x3c3e2e;
       numTxt.selectable=false;//
       numTxt.text = "文本显示内容";//顺序很重要
  }
 
 }
}

posted on 2013-07-24 14:31  维美启程  阅读(2425)  评论(0编辑  收藏  举报