Rotate Text Using Embedded Fonts in Actionscript 3

Rotate Text Using Embedded Fonts in Actionscript 3

I am working on a new AIR application where I will post more information about in the future…

I needed the ability to rotate text which I created dynamically, the answer was embedding!

Embedding fonts let’s you use custom fonts which must not be installed on a user his machine or PC ,
so there are more possibilities when using embedded fonts, but you must keep in mind is that embedding fonts
increases the file size of the compiled SWF file. This can be important when it comes to optimalization.

How can you embed the font in the Flex/Flash file?

First copy the specific font to the project folder , make a seperate map for example put it in Assets/fonts

Next you have to link the font to the flex file, this can be done using the Embed tag
embed1
As you can see on line 13 I create an instance for the fontClass, by doing thisĀ  it is possible to acctually use the font in the flex file, if you don’t they you will not be able to use the font!

next, I show you how I created the textfields:

createtext

As you can see on line 91 I enable font embedding on the textfield by setting te embedFonts property on true

on line 93 I call the initTextFormat function , in this function I will create a TextFormat and return it as shown below, once it is created I return it so it will be assigned as the defaulttextformat for the label

inittextformat

The font I use is called fontVerdana which is declared in the embed tag, so you can rename fonts in the embed tag, but then you have to call that embedded font with the custom given name!

now the text can be rotated, using a tween for example

tweener

as you can see it does not take much effort to embed fonts but it is very useful!

Advantages:

  • Use custom fonts without pushing the user of your application to have the used font installed on his machine
  • rotate and customize text dynamically

Disadvantages:

Increases the filesize of the compiled SWF file

Hope you enjoyed this article

About the Author

Lode is a Creative-Geek with passion for Graphic design , he is also into the web programming "stuff" like Adobe Flash,air and Flex . Lode loves to learn and loves to share knowledge with others.Follow Lode on http://twitter.com/stealfish