📄 tooltipmanager_old.as
字号:
package{
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.filters.DropShadowFilter;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.utils.Dictionary;
import flash.utils.clearInterval;
import flash.utils.setInterval;
import flash.utils.setTimeout;
import flash.utils.clearTimeout;
import flash.filters.BitmapFilterQuality;
import flash.text.TextFieldAutoSize;
public class ToolTipManager extends Sprite{
private var dict:Dictionary;
//仅使用文字
//private var tipText:TextField;
//private var filterArray:Array;
//private var filter:DropShadowFilter;
//private var textFormat:TextFormat;
//使用绘图方式
private const default_width:uint = 80;
private const default_height:uint = 25;
private const default_bgcolor:uint = 0xffffcc;
private const default_alpha:Number = 0.75;
private const default_x:int = 0;
private const default_y:int = 0;
private const default_textColorValue:uint = 0x000000;
private var widthValue:uint = default_width;
private var heightValue:uint = default_height;
private var bg_color:uint = default_bgcolor;
private var alphaValue:Number = default_alpha;
private var xValue:int = default_x;
private var yValue:int = default_y;
private var textColorValue:uint = default_textColorValue;
private var tipLabel:TextField;
private var textFormat:TextFormat;
private var filterArray:Array;
private var filter:DropShadowFilter;
private var stageX:int;
private var stageY:int;
private var stage_width:int;
private var stage_height:int;
private var timerId:uint;
public function ToolTipManager(stagewidth:int,stageheight:int){
super();
this.stage_width = stagewidth;
this.stage_height = stageheight;
trace(this.stage_width);
trace(this.stage_height);
}
public function setBgColor(newColor:uint):void{
this.bg_color = newColor;
}
public function setAlpha(newAlpha:Number):void{
this.alphaValue = newAlpha;
}
public function setTextColor(newColor:Number):void{
this.textColorValue = newColor;
}
public function createToolTip():void{
dict = new Dictionary();
//仅使用文字
/*
tipText = new TextField();
filterArray = new Array();
filter = new DropShadowFilter(5, 45, 0x000000, 1.0, 10, 10, 0.65, BitmapFilterQuality.MEDIUM, false, false);
filterArray.push(filter);
textFormat = new TextFormat("Verdana", 10, 0x000000);
tipText.filters = filterArray;
tipText.autoSize = TextFieldAutoSize.LEFT;
tipText.background = true;
tipText.backgroundColor = 0xfffeee;
tipText.border = true;
tipText.multiline = true;
tipText.selectable = false;
tipText.defaultTextFormat = textFormat;
tipText.visible = false;
addChild(tipText);
*/
//使用绘图方式
textFormat = new TextFormat();
textFormat.font = "Verdana";
textFormat.size = 12;
textFormat.color = textColorValue;
textFormat.leftMargin = 5;
textFormat.rightMargin = 5;
tipLabel = new TextField();
tipLabel.defaultTextFormat = textFormat;
tipLabel.multiline = true;
tipLabel.autoSize = TextFieldAutoSize.LEFT;
tipLabel.x = 10;
tipLabel.y = 10;
tipLabel.selectable = false;
filterArray = new Array();
filter = new DropShadowFilter(3, 45, 0x000000, 0.5, 5, 5, 0.65, BitmapFilterQuality.MEDIUM, false, false);
filterArray.push(filter);
this.filters = filterArray;
this.addChild(tipLabel);
this.visible = false;
}
public function addToolTip(key:DisplayObject,tipInfo:String):void{
dict[key] = tipInfo;
key.addEventListener(MouseEvent.MOUSE_OVER,mouseOverHdl);
key.addEventListener(MouseEvent.MOUSE_OUT,mouseOutHdl);
}
private function mouseOverHdl(me:MouseEvent):void{
var key:DisplayObject = me.currentTarget as DisplayObject;
//trace(key.x);
//trace(key.y);
//trace(key.width);
//trace(key.height);
//trace(me.stageX);
//trace(me.stageY);
//仅使用文字
//tipText.htmlText = dict[key];
//tipText.x = me.stageX + 13;
//tipText.y = me.stageY + 13;
//tipText.visible = true;
//使用绘图方式
tipLabel.htmlText = dict[key];
this.graphics.clear();
this.graphics.beginFill(bg_color,alphaValue);
//this.graphics.lineStyle(1,0xeeeeee,alphaValue);
//边缘检测
widthValue = tipLabel.width;
heightValue = tipLabel.height;
xValue = tipLabel.x;
yValue = tipLabel.y;
this.graphics.drawRoundRect(xValue,yValue,widthValue,heightValue,5,5);
trace(key.x + key.width/2 + widthValue);
trace(key.y + key.height/2 + heightValue + 10);
if(key.x + key.width/2 + widthValue < stage_width && key.y + key.height/2 + heightValue + 10 < stage_height){
//右下方显示
//this.graphics.drawRoundRect(xValue,yValue,widthValue,heightValue,5,5);
this.graphics.moveTo(0,0);
this.graphics.lineTo(xValue+widthValue/2 + 10,yValue);
this.graphics.lineTo(xValue+widthValue/2 - 10,yValue);
this.graphics.lineTo(0,0);
this.x = key.x + key.width/2;
this.y = key.y + key.height;
}else if(key.x + key.width/2 + widthValue >= stage_width && key.y + key.height/2 + heightValue + 10 < stage_height){
//左下方显示
//this.graphics.drawRoundRect(xValue,yValue,widthValue,heightValue,5,5);
this.graphics.moveTo(xValue+widthValue/2 + 20,0);
this.graphics.lineTo(xValue+widthValue/2 + 10,yValue);
this.graphics.lineTo(xValue+widthValue/2 - 10,yValue);
this.graphics.lineTo(xValue+widthValue/2 + 20,0);
this.x = key.x - widthValue/2 + 10;
this.y = key.y + key.height;
}else if(key.y + key.height/2 + heightValue + 10 >= stage_height && key.x >key.width/2){
//左上方显示
//this.graphics.drawRoundRect(xValue,yValue,widthValue,heightValue,5,5);
this.graphics.moveTo(xValue+widthValue/2 + 20,yValue + heightValue + 10);
this.graphics.lineTo(xValue+widthValue/2 + 10,yValue + heightValue);
this.graphics.lineTo(xValue+widthValue/2 - 10,yValue + heightValue);
this.graphics.lineTo(xValue+widthValue/2 + 20,yValue + heightValue + 10);
this.x = key.x - widthValue/2 + 20;
this.y = key.y - key.height - 20;
}else if(key.y + key.height/2 + heightValue + 10 >= stage_height && key.x<key.width/2){
//右上方显示
//this.graphics.drawRoundRect(xValue,yValue,widthValue,heightValue,5,5);
this.graphics.moveTo(xValue + 20,yValue + heightValue + 10);
this.graphics.lineTo(xValue+widthValue/2 + 10,yValue + heightValue);
this.graphics.lineTo(xValue+widthValue/2 - 10,yValue + heightValue);
this.graphics.lineTo(xValue + 20,yValue + heightValue + 10);
this.x = key.x + key.width/2 - 30;
this.y = key.y - key.height - 20;
}
this.graphics.endFill();
this.visible = true;
timerId = setTimeout(mouseOutHdl,2000,null);
me.updateAfterEvent();
}
private function mouseOutHdl(me:MouseEvent):void{
//仅使用文字
//tipText.htmlText = "";
//tipText.visible = false;
//使用绘图方式
tipLabel.htmlText = "";
this.visible = false;
clearTimeout(timerId);
}
public function destoryToolTip():void{
for(var key:Object in dict){
key.removeEventListener(MouseEvent.MOUSE_OVER,mouseOverHdl);
key.removeEventListener(MouseEvent.MOUSE_OUT,mouseOutHdl);
delete dict[key];
}
dict = null;
//仅使用文字
//textFormat = null;
//filter = null;
//filterArray = null;
//tipText= null;
//使用绘图方式
textFormat = null;
filter = null;
filterArray = null;
tipLabel= null;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -