Guest User

Untitled

a guest
Jan 24th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. package gui.cloud {
  2. import com.greensock.TweenMax;
  3.  
  4. import flash.display.Sprite;
  5. import flash.text.TextField;
  6. import flash.text.TextFieldAutoSize;
  7. import flash.text.TextFormat;
  8.  
  9. public class TextItem extends CloudItem {
  10. private var _color : int;
  11. private var _textfield : TextField;
  12. private var _textSize : int = 20;
  13. private var _background : Sprite;
  14. private var _fulltext : String;
  15. private var _color2 : uint;
  16.  
  17. public function TextItem(node : XML = null) {
  18. trace("TextItem() __construct");
  19. // if the super(node) is not invoked manually, the build fails with a null-reference error
  20. //super(node);
  21. _node = node;
  22. _color = 0x000000;
  23. _color2 = 0x000000;
  24. _active = false;
  25. _itemType = _node.type;
  26. _id = _node.id;
  27.  
  28. if (_itemType == "text") {
  29. _fulltext = _node.fulltext;
  30. }
  31. buildNode();
  32.  
  33. }
  34.  
  35. private function buildNode() : void {
  36. // build textfield for item
  37. _textfield = new TextField();
  38. _textfield.autoSize = TextFieldAutoSize.LEFT;
  39. _textfield.selectable = false;
  40. // set text styles
  41. var format : TextFormat = new TextFormat();
  42. format.font = "_Rockwell";
  43.  
  44. format.bold = (_itemType == "button") ? (true) : (false);
  45. format.italic = (_itemType == "button") ? (false) : (true);
  46. format.color = (_itemType == "button") ? (_color) : (_color2);
  47. format.size = _textSize;
  48. _textfield.defaultTextFormat = format;
  49. _textfield.embedFonts = true;
  50. // insert text
  51. _textfield.text = _node.content;
  52. addChild(_textfield);
  53. // _textfield.cacheAsBitmap = true;
  54. // center text
  55. _textfield.x = -this.width / 2;
  56. _textfield.y = -this.height / 2;
  57. // build background sprite
  58. _background = new Sprite();
  59. _background.graphics.beginFill(0x000000, 1);
  60. // _background.graphics.beginFill();
  61. _background.graphics.lineStyle(0);
  62. _background.graphics.drawRect(0, 0, _textfield.textWidth + 14, _textfield.textHeight + 6);
  63. _background.graphics.endFill();
  64. addChildAt(_background, 0);
  65. _background.x = -( _textfield.textWidth / 2 ) - 7;
  66. _background.y = -( _textfield.textHeight / 2 ) - 2;
  67. _background.alpha = 0;
  68. _background.visible = true;
  69. }
  70.  
  71. override public function setMouseOver() : void {
  72. TweenMax.killTweensOf(_background);
  73. super.setMouseOver();
  74. _textfield.textColor = 0xFFFFFF;
  75. _background.alpha = .35;
  76. }
  77.  
  78. override public function setMouseOut() : void {
  79. super.setMouseOut();
  80. _textfield.textColor = 0x000000;
  81. TweenMax.to(_background, 1, {alpha:0});
  82. }
  83.  
  84. public function get fulltext() : String {
  85. return _fulltext;
  86. }
  87. }
  88. }
Add Comment
Please, Sign In to add comment