AS3 TextHandle Util - TextField made easy


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

Very simple and basic TextHandle class, extends TextField... You can extend to fit your needs.

Basic usage:

var a:TextHandle = new TextHandle("some text");
addChild(a)

Optional params:

_size: uint ( default 22 ) - size of the textfiled

_color: uint ( default 0x000000, black ) - the color of the textfield


Copy this code and paste it in your HTML
  1. package {
  2.  
  3. import flash.text.TextField;
  4. import flash.text.AntiAliasType;
  5. import flash.text.Font;
  6. import flash.text.GridFitType;
  7. import flash.text.TextFieldAutoSize;
  8. import flash.text.TextFieldType;
  9. import flash.text.TextFormat;
  10. import flash.text.TextFormatAlign;
  11.  
  12. public class TextHandle extends TextField{
  13.  
  14. private var _format:TextFormat;
  15.  
  16. public function TextHandle(_label:String, _size:uint = 11, _color:uint = 0xFFFFFF) {
  17.  
  18. _format = new TextFormat();
  19. _format.font = "Verdana";
  20. _format.color = _color;
  21. _format.size = _size;
  22. _format.align = TextFormatAlign.LEFT;
  23.  
  24. this.embedFonts = false;
  25. this.antiAliasType = AntiAliasType.ADVANCED;
  26. this.autoSize = TextFieldAutoSize.LEFT;
  27. this.multiline = false;
  28. this.cacheAsBitmap = true;
  29. this.selectable = false;
  30. this.text = _label;
  31. this.defaultTextFormat = _format;
  32. this.setTextFormat(_format);
  33. }
  34.  
  35. public function get format():TextFormat{
  36. return _format;
  37. }
  38.  
  39. public function refresh():void{
  40. this.setTextFormat(_format);
  41. }
  42.  
  43. }//end
  44. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.