AS 3 EaseButton---継続自:EaseSprite


package
{
	import flash.display.Sprite;
	import flash.filters.GlowFilter;
	import flash.geom.Rectangle;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	/**
	 *  EasingButton , :text
	 *  , 
	 * @author Jave.Lin
	 */
	public class EaseButton extends EaseSprite
	{
		private var _text:String;
		
		public function get text():String{return _text;}
		public function set text(value:String):void
		{
			if(_text!=value)
			{
				_text=value;
				refresh();
			}
		}
		
		private var _textField:TextField;
		
		private var _isAutoSize:Boolean=true;
		
		public function get isAutoSize():Boolean{return _isAutoSize;}
		public function set isAutoSize(value:Boolean):void
		{
			if(_isAutoSize!=value)
			{
				_isAutoSize=value;
				refresh();
			}
		}
		// 
		private var _bgMargin:Number=2;
		
		public function EaseButton($text:String="button")
		{
			this.mouseChildren = false;
			
			text=$text;
			
			filters=[new GlowFilter(0,1,2,2,6)];
		}
		
		private function refresh():void
		{
			if(_textField==null)
			{
				//font Verdana
				_textField=new TextField();
				_textField.defaultTextFormat = new TextFormat("Verdana", 10, 0xffffff);
				_textField.autoSize = TextFieldAutoSize.LEFT;
				_textField.selectable = false;
				// 
				_textField.filters=[new GlowFilter(0,1,2,2,6)];
				addChild(_textField);
			}
			
			_textField.text=text;
			
			// 、 
			var textFieldRect:Rectangle=_textField.getBounds(this);
			
			// 
			_textField.x=-textFieldRect.width/2;
			_textField.y=-textFieldRect.height/2;
			
			// 
			this.graphics.clear();
			this.graphics.beginFill(0x55aa00, 0.5);
			this.graphics.drawRect(
				(-textFieldRect.width/2)-_bgMargin,
				(-textFieldRect.height/2)-_bgMargin,
				textFieldRect.width+(_bgMargin*2),
				textFieldRect.height+(_bgMargin*2)
			);
			this.graphics.endFill();
		}
	}
}