Embedding fonts in Flex Builder 3 using Actionscript 3

13 10 2009

I’ve been working on something that involves me doing some work with Flex and Actionscript. I needed to place a shape on my canvas and then write some text on that shape. The text field needed to be rotated by 90 degrees. All of the following needed to be done from the Actionscript. As you may already be aware, if I were to try and do this without embedding the font, the text would disappear. The best way I eventually found of embedding an existing system font was the following:

[Embed(systemFont='Franklin Gothic Medium', fontName="Franklin Gothic Medium", mimeType="application/x-font-truetype")]
const FONT_FRANKLIN:String;

Click here to read the full post and information on this code.

To then use this code with my text field, my code was as follows…

var format1:TextFormat = new TextFormat();
format1.font = "Franklin Gothic Medium";
format1.size = 14;
format1.align = "center";
var label1:TextField = new TextField();
label1.defaultTextFormat = format1;
label1.embedFonts = true;
label1.textColor = 0xFFFFFF;
label1.autoSize = TextFieldAutoSize.CENTER;
label1.text = "Connect";
label1.rotation = 90;

It is important to remember to set embedFonts to true, otherwise the text will still disappear!

Advertisements