Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package gui.cloud {
- import com.greensock.TweenMax;
- import flash.display.Sprite;
- import flash.text.TextField;
- import flash.text.TextFieldAutoSize;
- import flash.text.TextFormat;
- public class TextItem extends CloudItem {
- private var _color : int;
- private var _textfield : TextField;
- private var _textSize : int = 20;
- private var _background : Sprite;
- private var _fulltext : String;
- private var _color2 : uint;
- public function TextItem(node : XML = null) {
- trace("TextItem() __construct");
- // if the super(node) is not invoked manually, the build fails with a null-reference error
- //super(node);
- _node = node;
- _color = 0x000000;
- _color2 = 0x000000;
- _active = false;
- _itemType = _node.type;
- _id = _node.id;
- if (_itemType == "text") {
- _fulltext = _node.fulltext;
- }
- buildNode();
- }
- private function buildNode() : void {
- // build textfield for item
- _textfield = new TextField();
- _textfield.autoSize = TextFieldAutoSize.LEFT;
- _textfield.selectable = false;
- // set text styles
- var format : TextFormat = new TextFormat();
- format.font = "_Rockwell";
- format.bold = (_itemType == "button") ? (true) : (false);
- format.italic = (_itemType == "button") ? (false) : (true);
- format.color = (_itemType == "button") ? (_color) : (_color2);
- format.size = _textSize;
- _textfield.defaultTextFormat = format;
- _textfield.embedFonts = true;
- // insert text
- _textfield.text = _node.content;
- addChild(_textfield);
- // _textfield.cacheAsBitmap = true;
- // center text
- _textfield.x = -this.width / 2;
- _textfield.y = -this.height / 2;
- // build background sprite
- _background = new Sprite();
- _background.graphics.beginFill(0x000000, 1);
- // _background.graphics.beginFill();
- _background.graphics.lineStyle(0);
- _background.graphics.drawRect(0, 0, _textfield.textWidth + 14, _textfield.textHeight + 6);
- _background.graphics.endFill();
- addChildAt(_background, 0);
- _background.x = -( _textfield.textWidth / 2 ) - 7;
- _background.y = -( _textfield.textHeight / 2 ) - 2;
- _background.alpha = 0;
- _background.visible = true;
- }
- override public function setMouseOver() : void {
- TweenMax.killTweensOf(_background);
- super.setMouseOver();
- _textfield.textColor = 0xFFFFFF;
- _background.alpha = .35;
- }
- override public function setMouseOut() : void {
- super.setMouseOut();
- _textfield.textColor = 0x000000;
- TweenMax.to(_background, 1, {alpha:0});
- }
- public function get fulltext() : String {
- return _fulltext;
- }
- }
- }
Add Comment
Please, Sign In to add comment