BaseLabel.as 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* */
  2. package elements.labels {
  3. import flash.display.Sprite;
  4. import flash.display.Stage;
  5. import flash.text.TextField;
  6. import flash.text.TextFieldType;
  7. import flash.text.TextFormat;
  8. import flash.events.Event;
  9. import flash.text.TextFieldAutoSize;
  10. import string.Css;
  11. public class BaseLabel extends Sprite {
  12. public var text:String;
  13. protected var css:Css;
  14. public var style:String;
  15. protected var _height:Number;
  16. public function BaseLabel() {}
  17. protected function build( text:String ):void {
  18. var title:TextField = new TextField();
  19. title.x = 0;
  20. title.y = 0;
  21. this.text = text;
  22. title.htmlText = this.text;
  23. var fmt:TextFormat = new TextFormat();
  24. fmt.color = this.css.color;
  25. //fmt.font = "Verdana";
  26. fmt.font = this.css.font_family?this.css.font_family:'Verdana';
  27. fmt.bold = this.css.font_weight == 'bold'?true:false;
  28. fmt.size = this.css.font_size;
  29. fmt.align = "center";
  30. title.setTextFormat(fmt);
  31. title.autoSize = "left";
  32. title.y = this.css.padding_top+this.css.margin_top;
  33. title.x = this.css.padding_left+this.css.margin_left;
  34. // title.border = true;
  35. if ( this.css.background_colour_set )
  36. {
  37. this.graphics.beginFill( this.css.background_colour, 1);
  38. this.graphics.drawRect(0,0,this.css.padding_left + title.width + this.css.padding_right, this.css.padding_top + title.height + this.css.padding_bottom );
  39. this.graphics.endFill();
  40. }
  41. this.addChild(title);
  42. }
  43. public function get_width():Number {
  44. return this.getChildAt(0).width;
  45. }
  46. public function die(): void {
  47. this.graphics.clear();
  48. while ( this.numChildren > 0 )
  49. this.removeChildAt(0);
  50. }
  51. }
  52. }