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

Actions

Information

3 responses

16 10 2009
Polprav

Hello from Russia!
Can I quote a post in your blog with the link to you?

5 11 2009
Sarah

Yes no problem. Thanks for asking!

5 11 2009
streamvideo

amazing thanks a lot i had just searched a solution for autosize text.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: