views:

137

answers:

1

Hi,

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.

+2  A: 

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