您当前的位置: 首页 > 

Jave.Lin

暂无认证

  • 3浏览

    0关注

    704博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

AS3 EaseButton --- 继续自:EaseSprite

Jave.Lin 发布时间:2012-03-22 13:46:15 ,浏览量:3

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();
		}
	}
}
关注
打赏
1664331872
查看更多评论
立即登录/注册

微信扫码登录

0.0364s