SmartTip类是用来做气泡提示,演示如下:
使用方法:
1.创建tip:
SmartTip.createTip(target1_, "好好学习天天向上");
SmartTip.createTip方法接收四个参数:
target:DisplayObject 要提示的目标对象
content:*
提示的内容,必须是String或DisplayObject对象
location:String = null
提示在目标对象的方位。上下左右分别由SmartTip.TOP,
SmartTip.BOTTON,SmartTip.LEFT,SmartTip.RIGHT定义。默认为下方提示。
style:Object = null
提示的样式数据。不设置时使用默认样式。
该方法返回一个SmartTip示例。
2.设置tip样式:
tip的默认样式数据为:
{ arrowHeight:10, //箭头高度 arrowWidth:10, //箭头宽度 arrowIndentPercent:0, //箭头偏移量 backgroundGap:4, //边框间隔 backgroundCornerRadius:4, //圆角 backgroundIndentPercent:0, //背景偏移量 backgroundColor:0xffffff, //背景颜色 backgroundAlpha:1 //背景透明度 }
可以在使用SmartTip.createTip方法时,直接设置tip的样式:
//tip样式定义 var styleObj:Object = {arrowHeight:0, arrowWidth:0, arrowIndentPercent:0, backgroundGap:4, backgroundCornerRadius:4, backgroundIndentPercent:-100, backgroundColor:0xffffff, backgroundAlpha:0 }; SmartTip.createTip(target, "好好学习", martTip.TOP, styleObj);
或者在之后通过调用setStyle方法来更改样式:
var myTip:SmartTip = SmartTip.createTip(target1_, "好好学习天天向上"); //设置样式 myTip.setStyle("backgroundColor", 0x000000);
3.让tip在点击舞台其它地方时自动关闭:
var myTip:SmartTip = SmartTip.createTip(target1_, "好好学习天天向上"); //设置在tip外围点击后自动关闭tip myTip.closeOnClickOutside = true;//默认为true
4.设置tip停留一定时间后自动关闭:
var myTip:SmartTip = SmartTip.createTip(target1_, "好好学习天天向上"); //设置在5秒后自动关闭 myTip.setAutoClose(5000);//时间以毫秒为单位
5.设置tip显示关闭按钮,让用户可点击该按钮关闭tip:
var myTip:SmartTip = SmartTip.createTip(target1_, "好好学习天天向上"); //设置在5秒后自动关闭 myTip.setAutoClose(5000);//时间以毫秒为单位 //设置tip显示关闭按钮。关闭按钮将在tip的右上角显示 myTip.showCloseButton = true;//默认为false
6.关闭tip:
var myTip:SmartTip = SmartTip.createTip(target1_, "好好学习天天向上"); //关闭tip myRichTip.close();
7.SmartTip的常用静态控制方法:
//创建tip内容 var text:TextField = new TextField(); text.autoSize = TextFieldAutoSize.LEFT; text.text = “好好学习天天向上”; var myTip:SmartTip = SmartTip.createTip(target, text); //根据tip内容关闭tip。如果内容为String时,不可通过该方法删除对应的tip SmartTip.closeTipByContent(text): //关闭目标对象的所有tip SmartTip.closeTipsByTarget(target);