TextManager ActionScript 3.0 Class


/ Published in: ActionScript 3
Save to your folder(s)

Allows easy usage of Fonts and TextField/TextFormat creation.


Copy this code and paste it in your HTML
  1. package com.Zimsical.Typography {
  2.  
  3. import flash.display.Sprite;
  4. import flash.text.*;
  5.  
  6. public class TextManager extends Sprite {
  7.  
  8. public function TextManager() {
  9.  
  10. };
  11.  
  12. public static function CreateTextFormat(fontName:String, fontColor:Number, fontSize:uint, LetterSpacing:int):TextFormat {
  13. var _myTextFormat:TextFormat = new TextFormat;
  14. _myTextFormat.font = fontName;
  15. _myTextFormat.color = fontColor;
  16. _myTextFormat.letterSpacing = LetterSpacing;
  17. _myTextFormat.bold = false;
  18. _myTextFormat.size = fontSize;
  19. return _myTextFormat;
  20. };
  21.  
  22. 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 {
  23. ListFonts();
  24. var _myTextField:TextField = new TextField();
  25. var _myTextFormat:TextFormat = CreateTextFormat(fontName, txtColor, txtSize, LetterSpacing);
  26. _myTextFormat.kerning = Kerning;
  27. if (HTMLText == true) {
  28. _myTextField.htmlText = fontTxt;
  29. } else {
  30. _myTextField.text = fontTxt;
  31. };
  32. _myTextField.antiAliasType = "advanced";
  33. if (Multiline) {
  34. _myTextField.multiline = true;
  35. _myTextField.wordWrap = true;
  36. } else {
  37. _myTextField.multiline = false;
  38. _myTextField.wordWrap = false;
  39. };
  40. if (Input) {
  41. _myTextField.type = TextFieldType.INPUT;
  42. _myTextField.border = true;
  43. } else {
  44. _myTextField.type = TextFieldType.DYNAMIC;
  45. _myTextField.selectable = false;
  46. };
  47. _myTextField.embedFonts = true;
  48. _myTextField.setTextFormat(_myTextFormat);
  49. _myTextField.x = X;
  50. _myTextField.y = Y;
  51. _myTextField.autoSize = TextFieldAutoSize.LEFT;
  52. return _myTextField;
  53. };
  54.  
  55. private static function ListFonts():void {
  56.  
  57. var fonts:Array = Font.enumerateFonts();
  58. trace(fonts.length);
  59. var font:Font;
  60. for (var i:int; i<fonts.length;i++) {
  61. font = fonts[i];
  62. trace("name : "+font.fontName);
  63. trace("style : "+font.fontStyle);
  64. trace("type : "+font.fontType);
  65. };
  66.  
  67. };
  68.  
  69. };
  70.  
  71. };

URL: http://www.edwardhotchkiss.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.