⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cbutton.as

📁 as3.0 翻书效果
💻 AS
字号:
/**
* Description here..
* @author crlnet
* @version 1.1
*/

package crlclr.ui{

	import flash.display.DisplayObject;
	import flash.display.Shape;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.geom.Rectangle;
	import flash.text.*;
	import flash.text.TextFormat;

	public class cButton extends Sprite {
		private var w:int=80;
		private var h:int=30;
		private var padX:int=5;
		private var padY:int=5;
		private var title:String
		
		private var container:Sprite;
		private var icon:Sprite;
		private var titleF:TextField;
		private var bound:Rectangle
		private var btn:SimpleButton;
		
		
		private var upColor:uint   = 0xFFCC00;
		private var overColor:uint = 0xCCFF00;
		private var downColor:uint = 0x00CCFF;

		public function cButton(text:String,icon:Sprite) {
			this.title=text;
			this.icon=icon

			init()
			createChildren();
			resize();
		}
		private function init(){
			bound=new Rectangle(0,0,w,h);	
		}
		
		private function createChildren(){
			
			var downState:ButtonDisplayState= new ButtonDisplayState(downColor, bound);
			var overState:ButtonDisplayState= new ButtonDisplayState(overColor, bound);
			var upState:ButtonDisplayState= new ButtonDisplayState(upColor, bound);
			var hitTestState:ButtonDisplayState= new ButtonDisplayState(upColor, bound);

			btn=new SimpleButton(upState,overState,downState,hitTestState);
			btn.useHandCursor=true;
			
			
			container=new Sprite();
			
			container.addChild(icon);
			
			titleF=new TextField();
			titleF.defaultTextFormat=textFormat();
			titleF.text=title;
			titleF.selectable=false;
			titleF.autoSize=TextFieldAutoSize.LEFT;
			
			
			container.addChild(titleF);
			addChild(btn);
			addChild(container);
			
		}
		private function mindObject(o:DisplayObject){
			o.x=int(o.width/2);
			o.y=int(o.height/2);
		}
		private function textFormat():TextFormat {
			var mTextFormat = new TextFormat();
			mTextFormat.size = 12;
			mTextFormat.font = "Verdana";
			mTextFormat.color = 0x99999;
			return mTextFormat;
		}
		
		private function resize()
		{
			icon.y=(icon.height+icon.height)/2;
			icon.x=icon.width/2;
			titleF.x=icon.width;
			container.mouseEnabled=false;
			container.mouseChildren=false;
			//container.x=padX;
			
			container.x=int((w-container.width)/2)
			container.y=int((h-container.height)/2)
		}
		
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -