/ Published in: ActionScript 3
Allows easy usage of Fonts and TextField/TextFormat creation.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
package com.Zimsical.Typography { import flash.display.Sprite; import flash.text.*; public class TextManager extends Sprite { public function TextManager() { }; public static function CreateTextFormat(fontName:String, fontColor:Number, fontSize:uint, LetterSpacing:int):TextFormat { var _myTextFormat:TextFormat = new TextFormat; _myTextFormat.font = fontName; _myTextFormat.color = fontColor; _myTextFormat.letterSpacing = LetterSpacing; _myTextFormat.bold = false; _myTextFormat.size = fontSize; return _myTextFormat; }; public static function CreateTextField(LetterSpacing:int, Kerning:Boolean, X:int, Y:int, Input:Boolean, Multiline:Boolean, HTMLText:Boolean, txtSize:int, fontTxt:String, txtColor:Number, fontName:String):TextField { ListFonts(); var _myTextField:TextField = new TextField(); var _myTextFormat:TextFormat = CreateTextFormat(fontName, txtColor, txtSize, LetterSpacing); _myTextFormat.kerning = Kerning; if (HTMLText == true) { _myTextField.htmlText = fontTxt; } else { _myTextField.text = fontTxt; }; _myTextField.antiAliasType = "advanced"; if (Multiline) { _myTextField.multiline = true; _myTextField.wordWrap = true; } else { _myTextField.multiline = false; _myTextField.wordWrap = false; }; if (Input) { _myTextField.type = TextFieldType.INPUT; _myTextField.border = true; } else { _myTextField.type = TextFieldType.DYNAMIC; _myTextField.selectable = false; }; _myTextField.embedFonts = true; _myTextField.setTextFormat(_myTextFormat); _myTextField.x = X; _myTextField.y = Y; _myTextField.autoSize = TextFieldAutoSize.LEFT; return _myTextField; }; private static function ListFonts():void { var fonts:Array = Font.enumerateFonts(); trace(fonts.length); var font:Font; for (var i:int; i<fonts.length;i++) { font = fonts[i]; trace("name : "+font.fontName); trace("style : "+font.fontStyle); trace("type : "+font.fontType); }; }; }; };
URL: http://www.edwardhotchkiss.com