TextFormatter Class
I just posted on BulletBuilder. I realized there are two other classes I set up a while ago for another project that I use regularly that could use some explanation.
First is TextFormatter. We'd started a project and needed a quick way to implement some basic textfields across the project that could react to some supplied variables; font, color, size, leading
To circumvent some massive discussion about Stylesheets or whatever, I set up TextFormatter and it's done the job pretty adequately and I've used it since for anything non-complex in a textfield.
To use TextFormatter, just import the class and create a textfield then instantiate TextFormatter. Of course, also import the TextField class. You'll want to set the width of the textfield as well.
var tf:TextField = new TextField;
tf.width = 300;
new TextFormatter(tf,0x000000,12,"Flash ain't so bad","Arial");
addChild(tf);
Now in TextFormatter all the pseudo-heavy lifting can begin.
package com.utils {
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.text.AntiAliasType;
public class TextFormatter {
public function TextFormatter(src:TextField,fcolor:uint,fsize:Number,str:String,ffont:String="FranklinGothicEF-Demi", leading:Number=0)
{
src.autoSize = TextFieldAutoSize.LEFT;
src.background = false;
src.border = false;
src.embedFonts = true;
src.selectable = false;
src.antiAliasType = AntiAliasType.ADVANCED;
var format:TextFormat = new TextFormat;
format.font = ffont;
format.color = fcolor;
format.size = fsize;
format.leading = leading;
src.defaultTextFormat = format;
src.htmlText = str;
}
}
}
TextFormatter.as
Labels: AS3, flash, sample, TextFormatter



