Embedding Font Class in a Flash CS5 Component Class
I created a document class for a fla file which has
- font embedded
- traces the font info when the class is instantiated
- creates a text field to display embedded font
Here is the document class EmbedFontTest.as which is in the same directory as the Font Classes which it references(ArialEmbedder and MsRefEmbedder):
package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.Font;
import flash.text.TextFormat;
import flash.text.AntiAliasType;
public class EmbedFontTest extends Sprite {
//page 740 Essential Actionscript 3.0
//Force _ArialEmbedder and its fonts to be compiled into the swf
ArialEmbedder;
//MsRefEmbedder;
private var _text_fmt:TextFormat;
private var _text_txt:TextField;
public function EmbedFontTest() {
// constructor code
super();
var fonts:Array = Font.enumerateFonts();
fonts.sortOn("fontName", Array.CASEINSENSITIVE);
for (var i:int = 0; i< fonts.length; i++)
{
trace(fonts[i].fontName + "," + fonts[i].fontStyle + "," + fonts[i].fontType);
}
this.initEmbedFontTest();
}
private function initEmbedFontTest():void
{
this._text_fmt = new TextFormat();
//this._text_fmt.font = MsRefEmbedder.FONT_NAME;
this._text_fmt.font = ArialEmbedder.FONT_NAME;
this._text_fmt.size = 40;
this._text_fmt.bold = true;
this._text_fmt.italic = true;
this._text_txt = new TextField();
this._text_txt.embedFonts = true;
this._text_txt.autoSize = TextFieldAutoSize.LEFT;
this._text_txt.defaultTextFormat = this._text_fmt;
this._text_txt.text = "Test Text Format µ ≥";
this.addChild(this._text_txt);
}
}
}
Using the code above I was able to eliminate the font conflict I was running into when incorporating Flash CS5 swc component within a flex based project.
Advertisement
[...] in Series Part 5 Possibly related posts: (automatically generated)Flash CS3 using embedded fonts on TextField/Button [...]