zoukankan      html  css  js  c++  java
  • 简单纯文字浮动信息-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);
            }
    
        }
    }

    喜欢的可以拿过去哦~

  • 相关阅读:
    一首诗
    jsp作用域问题
    jsp关于request.setAttribue还有response.addCookie()的两个问题
    编程学习过程记录
    一些关于自己的未来的东西
    requests的post提交form-data; boundary=????
    记录一些爬虫的小细节
    【CSS3】CSS——链接
    【CSS3】CSS——文本
    【CSS3】background-clip与background-origin的联系与区别
  • 原文地址:https://www.cnblogs.com/LLLoveLL/p/3333216.html
Copyright © 2011-2022 走看看