AS3 ToolTip ---- 提示框类,细节是巨大滴魔鬼啊!

测试类:

package test
{
	import controlsEvents.CheckBoxEvent;
	
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import utils.StageManager;
	
	public class ToolTipTest extends Sprite
	{
		private var author:Label;
		private var tt:ToolTip;
		private var scrollerBt:Button;
		private var sizeBt:Button;
		private var directionBt:Button;
		private var d:int=0;
		private var carr:Array=[0xff0000,0x00ff00,0x0000ff,0xffff00,0x00ffff,0xff00ff,0x000000,0xffffff];
		private var ci:int=0;
		
		public function ToolTipTest()
		{
			super();
			
			StageManager.G_Stage=stage;
			
			stage.color=0xccccbb;
			stage.frameRate=60;
			stage.align=StageAlign.TOP_LEFT;
			stage.scaleMode=StageScaleMode.NO_SCALE;
			
			author=new Label();
			addChild(author);
			author.textColor=0x00ff00;
			author.fontSize=24;
			author.x=100;
			author.y=50;
			author.text="作者:Jave.Lin";
			
			tt=new ToolTip();
			addChild(tt);
//			tt.isAutoScroller=false;
			
			tt.x=100;
			tt.y=100;
			tt.width=200;
			tt.height=200;
			
			for (var i:int = 0; i < 20; i++) 
			{
				tt.text+="hello, i'm jave, this is my first toolTip Control~~~~\r\n";
			}
			
			scrollerBt=new Button();
			addChild(scrollerBt);
			scrollerBt.text="Scroller[truner]"
			
			scrollerBt.x=200;
			scrollerBt.y=200;
			
			scrollerBt.addEventListener(MouseEvent.CLICK,onScrollerBtClick);
			
			sizeBt=new Button();
			addChild(sizeBt);
			sizeBt.text="Size[truner]"
			
			sizeBt.x=200;
			sizeBt.y=225;
			
			sizeBt.addEventListener(MouseEvent.CLICK,onSizeBtClick);
			//directionBt
			directionBt=new Button();
			addChild(directionBt);
			directionBt.text="Direction[truner]"
			
			directionBt.x=200;
			directionBt.y=250;
			
			directionBt.addEventListener(MouseEvent.CLICK,onDirectionBtClick);
			
			ToolTip.setupToolTip(scrollerBt,tt);
			ToolTip.setupToolTip(sizeBt,tt);
			ToolTip.setupToolTip(directionBt,tt);
			
//			bt.addEventListener(MouseEvent.ROLL_OVER,onRollOver);
//			bt.addEventListener(MouseEvent.ROLL_OUT,onRollOut);
//			tt.addEventListener(MouseEvent.ROLL_OVER,onTTRollOver);
			
			//			Control.gc(tt);
			//			tt=null;
			
			stage.addEventListener(MouseEvent.CLICK,onClick);
			tt.backColor=carr[ci];
		}
		
		private function onClick(e:MouseEvent):void
		{
			ci++;
			if(ci>carr.length-1)ci=0;
			tt.backColor=carr[ci];
		}
		
		private function onScrollerBtClick(e:MouseEvent):void
		{
			tt.isAutoScroller=!tt.isAutoScroller;
		}
		
		private function onDirectionBtClick(e:MouseEvent):void
		{
			d++;
			if(d>3)d=0;
			switch(d)
			{
				case 0:
				{
					tt.shownDirection=ToolTipDirection.UP;
					break;
				}
				case 1:
				{
					tt.shownDirection=ToolTipDirection.DOWN;
					break;
				}
				case 2:
				{
					tt.shownDirection=ToolTipDirection.LEFT;
					break;
				}
				case 3:
				{
					tt.shownDirection=ToolTipDirection.RIGHT;
					break;
				}
					
				default:
				{
					break;
				}
			}
			tt.x=mouseX;
			tt.y=mouseY;
		}
		
		private function onSizeBtClick(e:MouseEvent):void
		{
			if(tt.hasEventListener(Event.ENTER_FRAME))
			{
				tt.removeEventListener(Event.ENTER_FRAME,onTTEnterFrame);
			}
			else
			{
				tt.addEventListener(Event.ENTER_FRAME,onTTEnterFrame);
			}
		}
		
		private var dW:Number=10;
		private var dH:Number=10;
		
		private function onTTEnterFrame(e:Event):void
		{
			if(tt.width<50 dw="10;" else="" if="" tt="" width="">300)dW=-10;
			
			if(tt.height<50 dh="10;" else="" if="" tt="" height="">300)dH=-10;
			
			tt.setWidthHeight(tt.width+dW,tt.height+dH);
		}
	}
}50>50>
下载运行实体: ToolTipTest.swf

运行图片效果:


因为有些坐标的东西,虽然可以想像得到,但,数据分类比较多,我还是手动的画在纸上:

查看全图


你可能感兴趣的:(Jave's,AS3-Control)