Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

as3 formatting a textfield

I'm dynamically creating textfields in as3, and formatting them with the TextFormat class. 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". Is there some way that I can specify this using the TextFormat class?

Thanks.

like image 271
minimalpop Avatar asked Nov 24 '25 12:11

minimalpop


1 Answers

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". I'm guessing the one you want is "TradeGothic Light Oblique", e.g.:

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:

var embeddedFontsOnly = Font.enumerateFonts(false);
like image 74
Ender Avatar answered Nov 26 '25 04:11

Ender



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!