Creating multiple SWF fonts through a custom extension panel
Date: 11 March 2010Step 1
Installing the fonts Make sure you have installed all the fonts you want to use.For Windows: Copy / paste them into C:\WINDOWS\Fonts\
For OSX: Double click the desired font(s) and click on the "Install font" button
Step 2
Install the ExportFonts extension Download the extension and install it by double clickingStep 3
Creating a new flash file Create a new Flash ActionScript 3.0 CS4 file (CTRL + N) and save it.Step 4
Launch Go to Window > Other panels > ExportFonts.You'll see a small multiline textfield with a few fonts seperated by a comma.
Fill in the installed fonts and press "GO!". A map swf_fonts is created where the exported SWF font files are exported to.
In the following steps I'll explain how you can use those fonts.
Using the font?
That's nice and all, but how do I use that font in my flash project?// Set up the textfield
var textField:TextField = new TextField();
textField.border = true;
textField.text = "This is standard text";
textField.width = 400;
textField.height = 200;
addChild(textField);
// Create a new TextFormat
var textFormat:TextFormat = new TextFormat();
// Load the actual font
function loadFont($fontName:String):void {
var fontLoader:Loader = new Loader();
fontLoader.load(new URLRequest("swf_fonts/font_" + $fontName +".swf"));
fontLoader.contentLoaderInfo.addEventListener(Event.INIT, fontInitialized);
// Internal function to handle the loaded font (swf)
function fontInitialized($e:Event):void {
$e.target.removeEventListener(Event.INIT, fontInitialized);
// The font is now loaded in the library.
textFormat.font = "font_" + $fontName;
// Make sure to allow embedding
textField.embedFonts = true;
textField.defaultTextFormat = textFormat;
// You have to reset the text, for the TextFormat to work properly
textField.text = textField.text;
}
}
loadFont("verdana");That's all.
Comments