【问题标题】:as3 formatting a textfieldas3 格式化文本字段
【发布时间】:2011-02-04 02:03:45
【问题描述】:

我在 as3 中动态创建文本字段,并使用 TextFormat 类对其进行格式化。我在选择字体的确切“样式”以应用于文本字段时遇到了一些问题。到目前为止,我的代码如下所示:

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

这可行(“Trade Gothic”应用于随附的文本),但我不知道如何应用“Trade Gothic”的特定样式,例如“Light Oblique”。有什么方法可以让我使用 TextFormat 类来指定它吗?

谢谢。

【问题讨论】:

    标签: flash actionscript-3 formatting fonts textfield


    【解决方案1】:

    你需要找到你想要的字体名称:

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

    您应该会看到多个“TradeGothic”列表。我猜你想要的是“TradeGothic Light Oblique”,例如:

    formatT.font = "TradeGothic Light Oblique";
    

    由于您的字体不是很常见,我建议您嵌入它 - 否则它不会在未安装该字体的计算机上正确呈现(请参阅here)。嵌入字体后,您必须指定:

    textItem.embedFonts = true;
    

    顺便说一句,如果您只想列出嵌入字体的名称,请为参数指定false

    var embeddedFontsOnly = Font.enumerateFonts(false);
    

    【讨论】:

      猜你喜欢
      • 2015-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-24
      相关资源
      最近更新 更多