ToolTip类代码如下:

?View Code ACTIONSCRIPT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package com.riaelite
{
	import flash.accessibility.AccessibilityProperties;
	import flash.display.*;
	import flash.events.*;
	import flash.geom.Point;
	import flash.text.*;
	/**
	 * @link kinglong@gmail.com
	 * @author Kinglong
	 * @version 0.1
	 * @since 20090608
	 * @playerversion fp9+
	 * 热区提示
	 */	
	public class ToolTip extends Sprite	{
		private static var instance:ToolTip = null;
		private var label:TextField;		
		private var area:DisplayObject;
		public function ToolTip() {
			label = new TextField();
			label.autoSize = TextFieldAutoSize.LEFT;
			label.selectable = false;
			label.multiline = false;
			label.wordWrap = false;
			label.defaultTextFormat = new TextFormat("宋体", 12, 0x666666);
			label.text = "提示信息";
			label.x = 5;
			label.y = 2;
			addChild(label);
			redraw();
			visible = false;
			mouseEnabled = mouseChildren = false;
		}
 
		private function redraw() {
			var w:Number = 10 + label.width;
			var h:Number = 4 + label.height;			
			this.graphics.clear();
			this.graphics.beginFill(0x000000, 0.4);
			this.graphics.drawRoundRect(3, 3, w, h, 5, 5);				
			this.graphics.moveTo(6, 3 + h);
			this.graphics.lineTo(12, 3 + h);
			this.graphics.lineTo(9, 8 + h);
			this.graphics.lineTo(6, 3 + h);
			this.graphics.endFill();
			this.graphics.beginFill(0xffffff);
			this.graphics.drawRoundRect(0, 0, w, h, 5, 5);
			this.graphics.moveTo(3, h);
			this.graphics.lineTo(9, h);
			this.graphics.lineTo(6, 5 + h);
			this.graphics.lineTo(3, h);
			this.graphics.endFill();
		}
 
		public static function init(base:DisplayObjectContainer) {
			if (instance == null) {
				instance = new ToolTip();
				base.addChild(instance);				
			}
		}
 
		public static function register(area:DisplayObject, message:String):void {
			if(instance != null){
				var prop:AccessibilityProperties = new AccessibilityProperties();
				prop.description = message;//在呈现辅助功能时为该显示对象提供一个说明
				area.accessibilityProperties = prop;//此显示对象的当前辅助功能选项
				area.addEventListener(MouseEvent.MOUSE_OVER, instance.handler);
			}
		}
 
		public static function unregister(area:DisplayObject):void {
			if (instance != null) {
				area.removeEventListener(MouseEvent.MOUSE_OVER, instance.handler);
			}
		}
 
		public function show(area:DisplayObject):void {
			this.area = area;
			this.area.addEventListener(MouseEvent.MOUSE_OUT, this.handler);
			this.area.addEventListener(MouseEvent.MOUSE_MOVE, this.handler);
			label.text = area.accessibilityProperties.description;
			redraw();			
		}
 
 
		public function hide():void	{
			this.area.removeEventListener(MouseEvent.MOUSE_OUT, this.handler);
			this.area.removeEventListener(MouseEvent.MOUSE_MOVE, this.handler);
			this.area = null;
			visible = false;
		}
 
		public function move(point:Point):void {			 
			var lp:Point = this.parent.globalToLocal(point);
			this.x = lp.x - 6;			
			this.y = lp.y - label.height - 12;
			if(!visible){
				visible = true;
			}
		}
 
		private function handler(event:MouseEvent):void	{
			switch(event.type) {
				case MouseEvent.MOUSE_OUT:
					this.hide();
					break;
				case MouseEvent.MOUSE_MOVE:
					this.move(new Point(event.stageX, event.stageY));					
					break;
				case MouseEvent.MOUSE_OVER:
					this.show(event.target as DisplayObject);
					this.move(new Point(event.stageX, event.stageY))
					break;
			}
		}		
	}
}

主文档类

?View Code ACTIONSCRIPT
1
2
3
4
5
6
7
8
9
10
11
import com.riaelite.ToolTip;
var base:Sprite = new Sprite();
addChild(base);
var sp:Sprite = new Sprite();
sp.mouseEnabled=sp.mouseChildren=false;
addChild(sp);
ToolTip.init(sp);
ToolTip.register(xxx_mc, "影片剪辑影片剪辑影片剪辑影片剪辑");
ToolTip.register(btn1, "按钮1");
ToolTip.register(btn2, "按钮2");
ToolTip.register(mytext, "这是一个动态文本");