AS3 - TextField:嵌入字体

Sal*_*ale 1 flash actionscript-3 flash-builder flash-builder4.5

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

drawText.embedFonts = false;
Run Code Online (Sandbox Code Playgroud)

渲染文本,但字体大小不会修改或颜色.

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
Run Code Online (Sandbox Code Playgroud)

非常令人沮丧的是,任何帮助都会受到高度赞赏.我正在使用Flash Builder 4.6.

fsb*_*ain 5

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

UPD:至于embedFonts你必须在使用之前注册字体类:

Font.registerFont(verdana);
Run Code Online (Sandbox Code Playgroud)

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";
Run Code Online (Sandbox Code Playgroud)