AS3 - 文本字段:嵌入字体 [英] AS3 - TextField: Embedded font

查看:194
本文介绍了AS3 - 文本字段:嵌入字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这code不会呈现文本到屏幕上。更改,

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

这真是令人沮丧的任何帮助将不胜AP preciated。我使用Flash Builder 4.6。

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

推荐答案

您应该适用 defaultTextFormat 设置前文或使用 TextField.setTextFormat 对于已有的文本

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

UPD: 而对于的embedFonts 您在使用之前注册的字体类型:

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

Font.registerFont(verdana);

UPD2:

UPD2:

例(修改code的话题):

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";

这篇关于AS3 - 文本字段:嵌入字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆