AS3 - TextField: Embedded font

眉间皱痕 提交于 2019-12-02 12:59:34

问题


This code will not render text to the screen. Changing,

drawText.embedFonts = false;

Renders text, but font size doesn't modify or the color.

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

It's really frustrating any help would be greatly appreciated. I'm using Flash Builder 4.6.


回答1:


You should apply defaultTextFormat before the setting of the text or use TextField.setTextFormat for the existed text

UPD: As for the embedFonts you have to register font class before using:

Font.registerFont(verdana);

UPD2:

Example (modify code in the topic):

   //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:


You should use drawText.setTextFormat(myFormat);



来源:https://stackoverflow.com/questions/17721804/as3-textfield-embedded-font

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!