简体   繁体   English

as3格式化文本字段

[英]as3 formatting a textfield

I'm dynamically creating textfields in as3, and formatting them with the TextFormat class. 我在as3中动态创建文本字段,并使用TextFormat类格式化它们。 I'm having some issues though with selecting the exact "style" of font to apply to the textfields. 我在选择要应用于文本字段的字体的确切“样式”时遇到了一些问题。 My code so far looks like: 到目前为止我的代码看起来像:

   formatT = new TextFormat( );
   formatT.bold = false; 
   formatT.color = 0x000000; 
   formatT.font = "TradeGothic";    
   formatT.size = 16;

    var textItem = new TextField();
    textItem.text = "foobar";
    textItem.setTextFormat(formatT);
    addChild(textItem);

This works ("Trade Gothic" is applied to the enclosed text), however I can't figure out how to apply a specific style of "Trade Gothic", for instance "Light Oblique". 这项工作(“贸易哥特式”适用于所附文本),但我无法弄清楚如何应用特定风格的“贸易哥特式”,例如“Light Oblique”。 Is there some way that I can specify this using the TextFormat class? 有没有办法可以使用TextFormat类指定它?

Thanks. 谢谢。

You need to find the name of the font you want: 您需要找到所需字体的名称:

var fonts = Font.enumerateFonts(true);
fonts.sortOn("fontName", Array.CASEINSENSITIVE);
for each(var f:Font in fonts)
     trace(f.fontName);

You should see multiple listings for "TradeGothic". 您应该会看到“TradeGothic”的多个列表。 I'm guessing the one you want is "TradeGothic Light Oblique", eg: 我猜你想要的是“TradeGothic Light Oblique”,例如:

formatT.font = "TradeGothic Light Oblique";

Since your font is not very common I would suggest embedding it - otherwise it won't render correctly on computers that don't have that font installed (see here ). 由于你的字体不常见,我建议嵌入它 - 否则它将无法在没有安装该字体的计算机上正确呈现(参见此处 )。 Once you embed the font, you have to specify: 嵌入字体后,您必须指定:

textItem.embedFonts = true;

btw, if you want to just list the names of embedded fonts, specify false for the parameter: 顺便说一句,如果你只想列出嵌入字体的名称,请为参数指定false

var embeddedFontsOnly = Font.enumerateFonts(false);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM