• 简单纯文字浮动信息-Tooltip


    分享个AS3 ToolTip类 纯文本

    效果预览:

    package ui
    {
        import flash.display.*;
        import flash.events.*;
        import flash.text.*;
    
        public class ToolTip {
    
            private static var tips:Array = [];
            private static var nowShowTip:DisplayObject;
            public static var isOn:Boolean = true;
    
            private static function hideTip(_arg1:MouseEvent):void{
                var textField:DisplayObjectContainer;
                textField = (_arg1.currentTarget.root as DisplayObjectContainer);
                nowShowTip.addEventListener(Event.ENTER_FRAME, alphaHide);
            }
            public static function findTip(_arg1:Object):String{
                var textField:Object;
                for each (textField in tips) {
                    if (textField[0] == _arg1){
                        return (textField[1]);
                    };
                };
                return ("tip");
            }
            private static function onOverTip(_arg1:MouseEvent):void {
                if (isOn == false) return;
                var textField:TextField;
                var sp:Sprite;
                var disContainer:DisplayObjectContainer;
                textField = new TextField();
                textField.width = 300;
                textField.height = 200;
                textField.textColor = 0xFFFFFF;
                textField.x = (3 + 4);
                textField.selectable = false;
                textField.htmlText = findTip(_arg1.currentTarget);
                textField.multiline = true;
                textField.wordWrap = true;
                textField.width = (textField.textWidth + 17);
                textField.height = (textField.textHeight + 5);
                textField.blendMode = BlendMode.LAYER;
                textField.setTextFormat(new TextFormat("Tahoma,Arial,Verdana"));
                sp = new Sprite();
                sp.graphics.beginFill(0x0099FF, 0.45);
                sp.graphics.lineStyle(1, 0x0099FF);
                sp.graphics.drawRoundRect(0.5, 0.5, (textField.width + 3), textField.height, 3, 3);
                sp.addChild(textField);
                sp.mouseEnabled = false;
                sp.mouseChildren = false;
                sp.visible = false;
                sp.alpha = 0;
                sp.addEventListener(Event.ENTER_FRAME, alphaShow);
                sp.cacheAsBitmap = true;
                disContainer = (_arg1.currentTarget.root as DisplayObjectContainer);
                disContainer.addChild(sp);
                nowShowTip = sp;
                moveTip(_arg1);
            }
            private static function alphaShow(_arg1:Event):void{
                var textField:DisplayObject;
                textField = (_arg1.currentTarget as DisplayObject);
                textField.alpha = (textField.alpha + 0.039);
                textField.visible = true;
                if (textField.alpha >= 1){
                    textField.removeEventListener(Event.ENTER_FRAME, alphaShow);
                };
            }
            private static function moveTip(_arg1:MouseEvent):void{
                var textField:DisplayObjectContainer;
                if (nowShowTip == null){
                    return;
                };
                textField = (_arg1.currentTarget.root as DisplayObjectContainer);
                nowShowTip.x = (textField.mouseX - 1);
                nowShowTip.y = (textField.mouseY + 22);
                if (nowShowTip.x > ((textField.stage.stageWidth - nowShowTip.width) - 2)){
                    nowShowTip.x = ((textField.stage.stageWidth - nowShowTip.width) - 2);
                };
                if (nowShowTip.y > ((textField.stage.stageHeight - nowShowTip.height) - 2)){
                    nowShowTip.y = ((textField.mouseY - nowShowTip.height) - 5);
                };
            }
            private static function alphaHide(_arg1:Event):void{
                var textField:DisplayObject;
                textField = (_arg1.currentTarget as DisplayObject);
                textField.alpha = (textField.alpha - 0.15);
                if (textField.alpha < 0.05){
                    textField.removeEventListener(Event.ENTER_FRAME, alphaHide);
                    textField.parent.removeChild(textField);
                };
            }
            public static function addText(_arg1:InteractiveObject, _arg2:String):void{
                tips.push([_arg1, _arg2]);
                _arg1.addEventListener(MouseEvent.MOUSE_OVER, onOverTip);
                _arg1.addEventListener(MouseEvent.MOUSE_OUT, hideTip);
                _arg1.addEventListener(MouseEvent.MOUSE_MOVE, moveTip);
            }
    
        }
    }

    喜欢的可以拿过去哦~

  • 相关阅读:
    自定义的弹出框列表适配器,类似于大众点评或美团
    Android 微信支付&支付宝支付
    动态设置 view 在布局中位置
    android 之图片异步加载
    android 侧滑菜单
    Google 官方 侧滑 drawerlayout
    python D27网络传输协议
    计算机单位换算、以及sort、sorted函数的区别
    python D26 socket、网络整个通信流程
    python D25 包
  • 原文地址:https://www.cnblogs.com/LLLoveLL/p/3333216.html
Copyright © 2020-2023  润新知