The intro:
Text that has been sent to a database by using “htmlText” instead of plain “text” has certain properties given with it such as ‘color’, ‘font’, etc… . Let’s say you push htmlText into a database and want to read it out in the frontend but you don’t want it to have that saved style. That’s where the textFormat class comes in.


The code:
It’s actually pretty simple once you get the hang of it. First of all you need to add your font to the library. You can do this by clicking on the small arrow with the three lines on the top right of the library panel:

fontscreen screenshot


In the menu that pops up you need to select the option “new Font…”. A box appears where you can set your font, fontname, style and size. By clicking “ok” you can see the font getting added to the library. Right-click it and give it a linkage name you can remember. I will use “Futura”.

From now on it’s just a few lines of code. Import the TextFormat class and if “automatically declare stage instances” is unchecked the font at the top of your class:

import flash.text.TextFormat;
import Futura;


Make an instance of your fontclass and an instance of the TextFormatClass and fill in the properties you want:

var fontFutura:Futura = new Futura();
 
var titleformat = new TextFormat();
titleformat.color = "0x000000";
titleformat.size = 12;
titleformat.font = fontFutura.fontName;


Finally set the textFormat of your textField to the newly created one:

textfield_txt.setTextFormat(titleformat);


Boom. Done.