论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > Flash AS教程
Tag:2.0,3.0菜鸟,游戏,,cs,技巧,源码,,文本,文字,函数,音乐,随机,拖拽,asp,access,xml,mc,视频教程

最新ToolTip类

文章类别:Flash AS | 发表日期:2009-8-7 12:21:09

最新ToolTip类

最近发现原来的那个ToolTip类使用起来还是不方便,故我又重新整理了一个更方便更灵活的ToolTip类.
新ToolTip类
复制内容到剪贴板代码:
package project.do93.pflip.view
{
   
    import flash.accessibility.AccessibilityProperties;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.Point;
    import flash.text.*;
    /**
     * @link kinglong@gmail.com
     * @author Kinglong
     * @version 0.1
     * @since 20090608
     * @playerversion fp9+
     * 热区提示
     */   
    public class ToolTip extends Sprite    {
        private static var instance:ToolTip = null;
        private var label:TextField;       
        private var area:DisplayObject;
        public function ToolTip() {
            label = new TextField();
            label.autoSize = TextFieldAutoSize.LEFT;
            label.selectable = false;
            label.multiline = false;
            label.wordWrap = false;
            label.defaultTextFormat = new TextFormat("宋体", 12, 0x666666);
            label.text = "提示信息";
            label.x = 5;
            label.y = 2;
            addChild(label);
            redraw();
            visible = false;
            mouseEnabled = mouseChildren = false;
        }
       
        private function redraw() {
            var w:Number = 10 + label.width;
            var h:Number = 4 + label.height;           
            this.graphics.clear();
            this.graphics.beginFill(0x000000, 0.4);
            this.graphics.drawRoundRect(3, 3, w, h, 5, 5);               
            this.graphics.moveTo(6, 3 + h);
            this.graphics.lineTo(12, 3 + h);
            this.graphics.lineTo(9, 8 + h);
            this.graphics.lineTo(6, 3 + h);
            this.graphics.endFill();
            this.graphics.beginFill(0xffffff);
            this.graphics.drawRoundRect(0, 0, w, h, 5, 5);
            this.graphics.moveTo(3, h);
            this.graphics.lineTo(9, h);
            this.graphics.lineTo(6, 5 + h);
            this.graphics.lineTo(3, h);
            this.graphics.endFill();
        }
       
        public static function init(base:DisplayObjectContainer) {
            if (instance == null) {
                instance = new ToolTip();
                base.addChild(instance);               
            }
        }
       
        public static function register(area:DisplayObject, message:String):void {
            if(instance != null){
                var prop:AccessibilityProperties = new AccessibilityProperties();
                prop.description = message;
                area.accessibilityProperties = prop;
                area.addEventListener(MouseEvent.MOUSE_OVER, instance.handler);
            }
        }
       
        public static function unregister(area:DisplayObject):void {
            if (instance != null) {
                area.removeEventListener(MouseEvent.MOUSE_OVER, instance.handler);
            }
        }
       
        public function show(area:DisplayObject):void {
            this.area = area;
            this.area.addEventListener(MouseEvent.MOUSE_OUT, this.handler);
            this.area.addEventListener(MouseEvent.MOUSE_MOVE, this.handler);
            label.text = area.accessibilityProperties.description;
            redraw();           
        }
       
        public function hide():void    {
            this.area.removeEventListener(MouseEvent.MOUSE_OUT, this.handler);
            this.area.removeEventListener(MouseEvent.MOUSE_MOVE, this.handler);
            this.area = null;
            visible = false;
        }
       
        public function move(point:Point):void {            
            var lp:Point = this.parent.globalToLocal(point);
            this.x = lp.x - 6;           
            this.y = lp.y - label.height - 12;
            if(!visible){
                visible = true;
            }
        }
       
        private function handler(event:MouseEvent):void    {
            switch(event.type) {
                case MouseEvent.MOUSE_OUT:
                    this.hide();
                    break;
                case MouseEvent.MOUSE_MOVE:
                    this.move(new Point(event.stageX, event.stageY));                   
                    break;
                case MouseEvent.MOUSE_OVER:
                    this.show(event.target as DisplayObject);
                    this.move(new Point(event.stageX, event.stageY))
                    break;
            }
        }
       
    }
}
调用实例
复制内容到剪贴板代码:
import project.do93.pflip.view.ToolTip;
var base:Sprite = new Sprite();
addChild(base);
var sp:Sprite = new Sprite();
sp.mouseEnabled=sp.mouseChildren=false;
addChild(sp);
//初始化ToolTip;
ToolTip.init(sp);
//与显示元素关联。
ToolTip.register(xxx_mc, "http://www.klstudio.com");
ToolTip.register(btn1, "我是按钮1");
ToolTip.register(btn2, "我是按钮2");

视频教程列表
文章教程搜索
 
Flash AS推荐教程
Flash AS热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058