package
{
import laya.net.Loader;
import laya.ui.Button;
import laya.ui.TipManager;
import laya.utils.Browser;
import laya.utils.Handler;
import ui.TestTipsUI;
public class ToolTipDemo
{
//ui弹框(IDE发布),用于鼠标悬浮提示框
private var _testTip:TestTipsUI;
private var _tip:TipManager;//实例化TipManager
public function ToolTipDemo()
{
Laya.init(Browser.width,Browser.height);
Laya.stage.bgColor="#eeffcc";
Laya.loader.load("res/atlas/comp.json",Handler.create(this,onLoaded),null,Loader.ATLAS);
}
private function onLoaded():void
{
this._testTip=new TestTipsUI();
//务必在Laya.init后去new实例,不可直接在全局变量处实例化
//切记,无论何种鼠标提示方式,务必要先实例化TipManager
//简单的鼠标提示可以直接new tipManager
this._tip=new TipManager();
//简单的鼠标提示
var button:Button=new Button();
Laya.stage.addChild(button);
button.label="button One";
button.pos(100,100);
button.skin="comp/button.png";
button.toolTip="我是button One!";
//自定义鼠标提示
var button2:Button=new Button();
Laya.stage.addChild(button2);
button2.label="button Two";
button2.pos(250,100);
button2.skin="comp/button.png";
button2.toolTip=Handler.create(this,showTips,null,false);
//携带参数的自定义鼠标提示
var button3:Button=new Button();
Laya.stage.addChild(button3);
button3.label="button Three";
button3.pos(400,100);
button3.skin="comp/button.png";
button3.toolTip=Handler.create(this,showTips2,["button Three"],false);
}
private function showTips():void
{
_testTip.my_label.text="我是button Two"
_tip.showDislayTip(_testTip);
}
private function showTips2(name:String):void
{
_testTip.my_label.text="我是:" name;
_tip.showDislayTip(_testTip);//自定义鼠标悬浮提示请用showDislayTip
}
}
}
去看TipManager.as源码,发现它并不是单例。也可以看到默认的TIPS:
public static var tipTextColor:String = "#ffffff";
public static var tipBackColor:String = "#111111";
public function TipManager() {
super();
_tipBox = new Component();
_tipBox.addChild(_tipText = new Text());
_tipText.x = _tipText.y = 5;
_tipText.color = tipTextColor;
_defaultTipHandler = _showDefaultTip;
Laya.stage.on(UIEvent.SHOW_TIP, this, _onStageShowTip);
Laya.stage.on(UIEvent.HIDE_TIP, this, _onStageHideTip);
this.zOrder = 1100
}
private function _showDefaultTip(text:String):void {
_tipText.text = text;
var g:Graphics = _tipBox.graphics;
g.clear();
g.drawRect(0, 0, _tipText.width + 10, _tipText.height + 10, tipBackColor);
addChild(_tipBox);
_showToStage(this);
Laya._currentStage.addChild(this);
}