[AS3]as3写的文字提示类toolTip类
[AS3]as3写的文字提示类toolTip类,自己写的一个toolTipWindow.as效果肯定没有kinglong的toolTip.as好. 只能暂时用着了
以前一直用kinglong写的toolTip类,挺好用的.但最近总出现问题,不是toolTip的错,应该是我使用不当:当有两帧时,每帧都需要热区 提示,但是翻来翻去就会出错,一直很郁闷.所以就自己写了一个toolTipWindow.as效果肯定没有kinglong的toolTip.as好. 只能暂时用着了,向大家学习中....
下在是类文件代码:
- package
- {
- import flash.display.DisplayObject;
- import flash.display.MovieClip;
- import flash.display.Sprite;
- import flash.display.Graphics;
- import flash.text.TextField;
- import flash.text.TextFieldAutoSize;
- import flash.text.TextFormat;
- import flash.events.MouseEvent;
- import flash.events.Event;
- import flash.geom.Point;
- import flash.display.DisplayObjectContainer;
- /**
- * ...文字提示类用法...
- * @author zkl
- * @time 2010-7-27
- * @QQ:344209679
- */
- public class toolTipWindow extends Sprite
- {
- private var _sprite:Sprite;
- private var _label:TextField;
- private var obj:DisplayObjectContainer;
- private var mc:DisplayObject;
- private var str:String;
- /**
- * ...构造函数
- * 参数:显示对象容器,显示对象,显示内容
- * 如:new toolTipWindow(this, titleTS, "我是中国人");
- */
- public function toolTipWindow(obj:DisplayObjectContainer,mc:DisplayObject,str:String):void
- {
- this.obj = obj;
- this.mc = mc;
- this.str = str;
- init();
- }
- private function init():void
- {
- drawRect();
- configListener();
- }
- /**
- * ...
- * 配置鼠标事件 CuPlayer.com
- */
- private function configListener():void
- {
- mc.addEventListener(MouseEvent.MOUSE_OVER, mouseHandler);
- mc.addEventListener(MouseEvent.MOUSE_MOVE, mouseHandler);
- mc.addEventListener(MouseEvent.MOUSE_OUT, mouseHandler);
- mc.addEventListener(Event.REMOVED_FROM_STAGE, removeListener);
- }
- /**
- * ...
- * 鼠标事件监听
- */
- private function mouseHandler(e:MouseEvent):void
- {
- switch(e.type) {
- case MouseEvent.MOUSE_OVER:
- _sprite.x = obj.mouseX - 5;
- _sprite.y = obj.mouseY - _sprite.height - 10;
- _sprite.visible = true;
- break;
- case MouseEvent.MOUSE_MOVE:
- _sprite.x = obj.mouseX - 5;
- _sprite.y = obj.mouseY - _sprite.height - 10;
- break;
- case MouseEvent.MOUSE_OUT:
- _sprite.visible = false;
- break;
- }
- }
- /**
- * ...
- * 显示提示框 CuPlayer.com
- */
- private function drawRect():void
- {
- _sprite = new Sprite;
- obj.addChild(_sprite);
- _label = new TextField;
- _label.autoSize = TextFieldAutoSize.LEFT;
- _label.defaultTextFormat = new TextFormat("宋体", 14, 0x000000);
- _label.selectable = false;
- _label.multiline = false;
- _label.wordWrap = false;
- _label.text = str;
- _sprite.addChild(_label);
- _label.x = 5;
- _label.y = 2;
- var w:Number = 10 + _label.width;
- var h:Number = 4 + _label.height;
- _sprite.graphics.clear();
- _sprite.graphics.beginFill(0x000000, 0.4);
- _sprite.graphics.drawRoundRect(3, 3, w, h, 5, 5);
- _sprite.graphics.moveTo(6, 3 + h);
- _sprite.graphics.lineTo(12, 3 + h);
- _sprite.graphics.lineTo(9, 8 + h);
- _sprite.graphics.lineTo(6, 3 + h);
- _sprite.graphics.endFill();
- _sprite.graphics.beginFill(0xFFFFCC);
- _sprite.graphics.drawRoundRect(0, 0, w, h, 5, 5);
- _sprite.graphics.moveTo(3, h);
- _sprite.graphics.lineTo(9, h);
- _sprite.graphics.lineTo(6, 5 + h);
- _sprite.graphics.lineTo(3, h);
- _sprite.graphics.endFill();
- _sprite.visible = false;
- }
- /**
- * ...
- * 删除监听
- */
- private function removeListener(e:Event):void
- {
- mc.removeEventListener(MouseEvent.MOUSE_OVER, mouseHandler);
- mc.removeEventListener(MouseEvent.MOUSE_MOVE, mouseHandler);
- mc.removeEventListener(MouseEvent.MOUSE_OUT, mouseHandler);
- mc.removeEventListener(Event.REMOVED_FROM_STAGE, removeListener);
- _sprite.visible = false;
- _sprite.removeChild(_label);
- obj = null;
- mc = null;
- str = null;
- }
- }
- }
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例
请稍候...