Guest User

Untitled

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