Posted in as3 by nicoB on March 2nd, 2008

In my last project I lost some time just to set a textformat to a simple textfield. The font was well linked in the librairy, but the textformat (particularly the font) didn’t apply to the textfield.

I found the reason : flash renames bitmap fonts and adds the suffix : _SIZEpt_st.

- Verdana becomes Verdana_12pt_st
- Arial becomes Arial_12pt_st
- etc.


For example : You want to use a Verdana Bitmap 12px :

Create a new Font in the library, and export it to Actionscript :

bitmap_check

If you create a TextFormat and Apply “Verdana” font, it won’t work :

import flash.text.TextField;
import flash.text.TextFormat;

//create Textfield
var txt : TextField = new TextField();
txt.width = 200;
txt.height = 20;
txt.text = "I’m not in Verdana Bitmap";
addChild(txt);

//apply textformat
var format : TextFormat = new TextFormat();
format.font = "Verdana";
txt.setTextFormat(format);

The reason is : the font is renamed to “Verdana_12pt_st” :

import flash.text.TextField;
import flash.text.TextFormat;

//create Textfield
var txt : TextField = new TextField();
txt.width = 200;
txt.height = 20;
txt.text = "I’m in Verdana Bitmap";
addChild(txt);

//apply textformat
var format : TextFormat = new TextFormat();
format.font = "Verdana_12pt_st";
txt.setTextFormat(format);

The trick to get the embedded fonts list on your flash file:

import flash.text.Font;

var embeddedFonts:Array = Font.enumerateFonts(false);
for (var i:uint = 0; i < embeddedfonts.length; i++){
     var f : Font  = embeddedFonts[i];
     trace(f.fontName);
}

List of replies :

  1. Monsieur.VD., says

    wow it’s good to know that !



  2. Fardeen, says

    Merci , on comprend mieux pourquoi un bon flasheur est un flasheur qui connait les bugs

    Et félicitation, être cité sur le blog PV3D, c’est la classe



  3. See-ming Lee, says

    Great to know–how did you find this out?


Leave a Reply