本脚本适用于Flash 8.0(AS2)
新建一个Fla文件,画一个影片剪辑拖入场景三次,分别取名叫:mc,mc2,mc3,并新建一层,将下面的代码复制进去
将下面文件保存成:ToolTips.as
import Shape;
class ToolTips {
public var toolTips:MovieClip;
public var toolTipsBase:MovieClip;
public var hitMCArray:Array;
public var levelMC:MovieClip;
public var fmt:TextFormat;
public var boxArray:Array;
public var toolTipsBaseColor:String;
public var toolTipsBaseAlpha:Number;
public var toolTipsBaseLineColor:String;
public var toolTipsBaseLineWidth:Number;
function ToolTips(levelMC,hitMCArray){
this.levelMC = levelMC;
this.hitMCArray = hitMCArray;
setBox();
setTipsTextFormat();
}
public function setToolTips(mc){
var l = this.hitMCArray.length;
var hitMCArray = this.hitMCArray;
var toolTipsBase = this.toolTipsBase;
var hit:Number = 0;
var fmt:TextFormat = this.fmt;
var boxArray:Array = this.boxArray;
this.toolTips = levelMC.createEmptyMovieClip("toolTips",levelMC.getNextHighestDepth());
this.toolTipsBase = toolTips.createEmptyMovieClip("toolTipsBase",toolTips.getNextHighestDepth());
Shape.box(this.toolTipsBase,0,0,200,20,[this.toolTipsBaseLineColor,this.toolTipsBaseLineWidth],[this.toolTipsBaseColor,this.toolTipsBaseAlpha]);
this.toolTips.createTextField("txt", 1, 2, 3, 400, 25);
this.toolTips._visible = false;
}
public function setBox(lineArray:Array,baseArray:Array){
if(lineArray == undefined && baseArray == undefined){
this.toolTipsBaseColor = "0xFFFFCC";
this.toolTipsBaseLineWidth = 1;
this.toolTipsBaseLineColor = "0x999999";
this.toolTipsBaseAlpha = 100;
}else if(lineArray == undefined){
this.toolTipsBaseLineColor = "0x999999";
this.toolTipsBaseLineWidth = 1;
this.toolTipsBaseColor = baseArray[0];
this.toolTipsBaseAlpha = baseArray[1];
}else if(baseArray == undefined){
this.toolTipsBaseLineColor = lineArray[0];
this.toolTipsBaseLineWidth = lineArray[1];
this.toolTipsBaseColor = "0xFFFFCC";
this.toolTipsBaseAlpha = 100;
}else{
var array:Array = new Array();
this.toolTipsBaseLineColor = lineArray[0];
this.toolTipsBaseLineWidth = lineArray[1];
this.toolTipsBaseColor = baseArray[0];
this.toolTipsBaseAlpha = baseArray[1];
}
}
public function setBoxFormat(boxFormat){
}
public function setTipsTextFormat(_fmt){
if(_fmt == undefined || _fmt == null){
var fmt:TextFormat = new TextFormat();
fmt.size = 12;
fmt.font = "宋体";
this.fmt = fmt;
}else{
this.fmt = _fmt;
}
}
public function hitCheck(){
var l = this.hitMCArray.length;
this.toolTips._x = _xmouse +10;
this.toolTips._y = _ymouse +10;
this.toolTips._visible = false;
for(var i = 0 ;i < l; i++){
if(this.hitMCArray[i].hitTest(_xmouse, _ymouse, true)){
var str:String = this.hitMCArray[i].tooltipText;
if(str.length != 0 && str != undefined){
this.toolTips.toolTipsBase._width = (str.length * this.fmt.size) + 10;
this.toolTips.toolTipsBase._height = (this.fmt.size) + 12;
this.toolTips._visible = true;
this.toolTips.txt.text = str;
this.toolTips.txt.setTextFormat(this.fmt);
}
}
}
}
}
将下面脚本保存成:Shape.as
class Shape {
public static function line(mc :MovieClip,
x1 :Number,
y1 :Number,
x2 :Number,
y2 :Number,
line:Array) : Void {
if(line[1] == undefined){line[1] = 1;}
if(line[0] == undefined){line[0] = 0x000000;}
if (line[1] == 0) {
mc.lineStyle();
}else{
mc.lineStyle(line[1],line[0]);
}
mc.beginFill();
mc.moveTo(x1, y1);
mc.lineTo(x2, y2);
mc.lineTo(x1, y1);
mc.endFill();
}
public static function box(mc:MovieClip,
x1 :Number,
y1 :Number,
width :Number,
hight :Number,
line :Array,
base :Array) : Void {
if(line[1] == undefined){line[1] = 1 }
if(line[0] == undefined){line[0] = 0x000000;}
if (line[0] == 0) {
mc.lineStyle();
}else{
mc.lineStyle(line[1],line[0]);
}
if(base[0] == undefined || base[0] == null){
mc.beginFill();
}else{
if(base.length > 2){
mc.beginGradientFill(base[0],base[1],base[2],base[3],base[4]);
}else{
mc.beginFill(Number(base[0]),Number(base[1]));
}
}
mc.moveTo(x1, y1);
mc.lineTo(x1 + width, y1);
mc.lineTo(x1 + width, y1 + hight);
mc.lineTo(x1, y1 + hight);
mc.lineTo(x1, y1);
mc.endFill();
}
public static function ginkgoCircle(mc:MovieClip,
nX:Number,
nY:Number,
nR:Number,
nStD :Number,
nInD :Number,
line :Array,
base :Array) : Void {
if(line[1] == undefined){line[1] = 1;}
if(line[0] == undefined){line[0] = 0x000000;}
if (line[1] == 0) {
mc.lineStyle();
}else{
mc.lineStyle(line[1],line[0]);
}
if(base == undefined || base == null){
mc.beginFill();
}else{
if(base.length > 2){
mc.beginGradientFill(base[0],base[1],base[2],base[3],base[4]);
}else{
mc.beginFill(Number(base[0]),Number(base[1]));
}
}
var segmentDegrees :Number = 45;
if(nInD <= segmentDegrees){
var pointlist :Array
= __ginkgoCircleBitPoint(nX,nY,nR,nStD,nInD);
mc.moveTo(pointlist[0], pointlist[1]);
mc.lineTo(pointlist[2], pointlist[3]);
mc.curveTo(pointlist[6], pointlist[7],
pointlist[4], pointlist[5]);
mc.lineTo(pointlist[0], pointlist[1]);
}else{
var segme :Number = Math.floor(nInD / segmentDegrees);
var amari :Number = nInD % segmentDegrees;
if(amari != 0){
var pointlist :Array
= __ginkgoCircleBitPoint(nX,nY,nR,nStD,amari);
mc.moveTo(pointlist[0], pointlist[1]);
mc.lineTo(pointlist[2], pointlist[3]);
mc.curveTo(pointlist[6], pointlist[7],
pointlist[4], pointlist[5]);
};
var deg = amari;
for(var i=0;i<segme;i++){
var pointlist :Array = __ginkgoCircleBitPoint
(nX,nY,nR,
nStD + deg + i * segmentDegrees,
segmentDegrees);
if(i == 0 && amari == 0){
mc.moveTo(pointlist[0], pointlist[1]);
mc.lineTo(pointlist[2], pointlist[3]);
}
mc.curveTo(pointlist[6], pointlist[7],
pointlist[4], pointlist[5]);
if(i == segme - 1){
mc.lineTo(pointlist[0], pointlist[1]);
}
}
}
mc.endFill();
}
private static function __ginkgoCircleBitPoint(nX :Number,
nY :Number,
nR :Number,
nStD :Number,
nInD :Number) : Array {
var raStD = nStD * Math.PI / 180;
var raInD = nInD * Math.PI / 180;
var nS1X :Number = nX + (nR * Math.cos(raStD));
var nS1Y :Number = nY + (nR * Math.sin(raStD));
var nSLX :Number = nX + (nR * Math.cos(raStD + raInD));
var nSLY :Number = nY + (nR * Math.sin(raStD + raInD));
var nCtlX :Number = nSLX + nR * Math.tan(raInD/2)
* Math.cos(raStD + raInD - Math.PI/2);
var nCtlY :Number = nSLY + nR * Math.tan(raInD/2)
* Math.sin(raStD + raInD - Math.PI/2);
return [nX,nY,nS1X,nS1Y,nSLX,nSLY,nCtlX,nCtlY];
}
public static function circle(target_mc:MovieClip,
nX:Number,
nY:Number,
nR:Number,
line:Array,
base:Array):Void {
}
public static function octagonbox(mc:MovieClip,
x1:Number,
y1:Number,
width:Number,
hight:Number,
round:Number,
line:Array,
base:Array) : Void {
if(line[1] == undefined){line[1] = 1;}
if(line[0] == undefined){line[0] = 0x000000;}
if (line[1] == 0) {
mc.lineStyle();
}else{
mc.lineStyle(line[1],line[0]);
}
if(base == undefined || base == null){
mc.beginFill();
}else{
if(base.length > 2){
mc.beginGradientFill(base[0],base[1],base[2],base[3],base[4]);
}else{
mc.beginFill(Number(base[0]),Number(base[1]));
}
}
if(round == undefined || isNaN(round) == true){
round = 0;
}
if(0 > (width - round) || 0 > (hight - round) ){
round = 0;
}
if(width > 0){
mc.moveTo(x1 + round, y1);//1
mc.lineTo(x1 + width - round, y1);//2
mc.lineTo(x1 + width, y1 + round);//3
mc.lineTo(x1 + width, y1 + hight - round);//4
mc.lineTo(x1 + width - round, y1 + hight);//5
mc.lineTo(x1 + round, y1 + hight);//6
mc.lineTo(x1 , y1 + hight - round);//7
mc.lineTo(x1 , y1 + round);//8
mc.lineTo(x1 + round, y1);//9
mc.endFill();
}else{
mc.moveTo(x1, y1);
mc.lineTo(x1 + 1, y1);
mc.lineTo(x1 + 1, y1 + hight);
mc.lineTo(x1, y1 + hight);
mc.lineTo(x1, y1);
mc.endFill();
}
}
public static function roundbox(mc:MovieClip,
x1:Number,
y1:Number,
width:Number,
hight:Number,
round:Array,
line:Array,
base:Array) : Void {
if(line[1] == undefined){line[1] = 1;}
if(line[0] == undefined){line[0] = 0x000000;}
if (line[1] == 0) {
mc.lineStyle();
}else{
mc.lineStyle(line[1],line[0]);
}
if(base == undefined || base == null){
mc.beginFill();
}else{
if(base.length > 2){
mc.beginGradientFill(base[0],base[1],base[2],base[3],base[4]);
}else{
mc.beginFill(Number(base[0]),Number(base[1]));
}
}
if(round == undefined || round.length < 0 ){
var round:Array = [0,0,0,0];
}
if(0 > (width - round[0]) || 0 > (hight - round[0]) ){
var round:Array = [0,0,0,0];
}
if(width > 0){
if(width - (round[2]*2) < 0){
round[2] = width;
}
mc.moveTo(x1 + round[0], y1);//1
mc.lineTo(x1 + width - round[2], y1);//2
mc.curveTo(x1 + width , y1 ,x1 + width ,y1 + round[3]);
mc.lineTo(x1 + width, y1 + round[3] );//3
mc.lineTo(x1 + width, y1 + hight - round[3] );//4
mc.curveTo(x1 + width , y1 + hight, x1 + width - round[2] , y1 + hight);
mc.lineTo(x1 + width - round[2], y1 + hight);//5
mc.lineTo(x1 + round[0], y1 + hight );//6
mc.curveTo(x1, y1+ hight, x1,y1+hight- round[1]);
mc.lineTo(x1 , y1 + hight - round[1]); //7
mc.lineTo(x1 , y1 + round[1]); //8
mc.curveTo(x1, y1, x1 + round[0],y1);
mc.lineTo(x1 + round[0], y1);//9
mc.endFill();
}else{
mc.moveTo(x1, y1);
mc.lineTo(x1 + 1, y1);
mc.lineTo(x1 + 1, y1 + hight);
mc.lineTo(x1, y1 + hight);
mc.lineTo(x1, y1);
mc.endFill();
}
}
}
新建一个Fla文件,画一个影片剪辑拖入场景三次,分别取名叫:mc,mc2,mc3,并新建一层,将下面的代码复制进去
import ToolTips;
var tooltips:ToolTips = new ToolTips(this,[mc,mc2,mc3]);
mc.tooltipText = "提示内容";
mc2.tooltipText = "提示内容2";
mc3.tooltipText = "提示内容3";
tooltips.setToolTips();
var mouseListener:Object = new Object();
mouseListener.onMouseMove = function() {
tooltips.hitCheck();
};
Mouse.addListener(mouseListener);
注意:ToolTips.as 和 Shape.as 和 你的fla文件要放在同一目录。
声明:类文件是小日本所写,我只是整理了一下,并附上了使用方法。
效果如下: