【问题标题】:AS3 - TextField: Embedded fontAS3 - TextField:嵌入字体
【发布时间】:2013-07-17 07:20:08
【问题描述】:

此代码不会将文本呈现到屏幕上。改变,

drawText.embedFonts = false;

呈现文本,但不修改字体大小或颜色。

package {

import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.*;

public class DrawText extends Sprite {

    private var drawText:TextField;
    private var myFormat:TextFormat;

    [Embed(source="c:/windows/fonts/verdana.ttf", fontFamily="Verdana", embedAsCFF="false")]
    private var verdana:Class;
    public function DrawText(mX:int,mY:int){

        myFormat = new TextFormat("Verdana");
        myFormat.size = 32;
        myFormat.color = 0x00FFFF;

        drawText = new TextField();
        drawText.embedFonts = true;
        drawText.autoSize = TextFieldAutoSize.LEFT;
        drawText.selectable = false;
        drawText.type = "dynamic";
        drawText.multiline=true;
        drawText.wordWrap=true;
        drawText.x = 128;
        drawText.y = 128;
        drawText.text = "TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST";
        drawText.defaultTextFormat = myFormat;
        addChild(drawText);

    }//END constructor

}//END class

}//END package

真是令人沮丧,任何帮助将不胜感激。我使用的是 Flash Builder 4.6。

【问题讨论】:

    标签: actionscript-3 flash flash-builder flash-builder4.5


    【解决方案1】:

    您应该在设置text 之前应用defaultTextFormat 或为现有文本使用TextField.setTextFormat

    更新: 至于embedFonts,使用前必须先注册字体类:

    Font.registerFont(verdana);
    

    UPD2:

    示例(修改主题中的代码):

       //set defaultTextFormat before set text 
       //and use setTextFormat to format existed text 
       drawText.defaultTextFormat = myFormat;
       drawText.setTextFormat(myFormat);
       drawText.text = "TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST";
    

    【讨论】:

    • 你刚刚打败了我!我只是想通了!快把我逼疯了!这是答案,但你回复得太快了,我还不能标记它!谢谢!
    • 你能写一个这样的例子吗?谢谢...我遇到了一些问题
    【解决方案2】:

    你应该使用drawText.setTextFormat(myFormat);

    【讨论】:

      猜你喜欢
      • 2012-10-10
      • 2011-12-10
      • 2011-11-16
      • 1970-01-01
      • 2013-03-05
      • 2011-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多