As3 text field formatting

I am dynamically creating text fields in as3 and formatting them using the TextFormat class. I am having some problems though with choosing the exact "style" of the font to apply to text fields. My code looks like this:

   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" applies to the attached text), however I cannot figure out how to apply a specific "Trade Gothic" style, such as "Light Oblique". Is there a way to specify this using the TextFormat class?

Thank.

+3
source share
1 answer

You need to find the name of the desired font:

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

, , , (. ). , :

textItem.embedFonts = true;

btw, , false :

var embeddedFontsOnly = Font.enumerateFonts(false);
+4

Source: https://habr.com/ru/post/1739722/


All Articles