WHAT'S NEW?
Loading...

ToolTip class As3


package com.PustakaFlash.Display
{
    import flash.display.MovieClip;
    import flash.display.Stage;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;
    
    /**
  * import com.PustakaFlash.Display.*;
  var tes:Tooltip=new Tooltip();
  var isitooltips:Vector;
  Tooltip.SetupStage(stage);
  Tooltip.ConfigureTooltip(true,true,0xFFFF99);
  Tooltip.ConfigureTextTooltip();
  btn.addEventListener(MouseEvent.MOUSE_OVER, tmpil("saya adalah tooltip pertama"));
  btn2.addEventListener(MouseEvent.MOUSE_OVER, tmpil("saya adalah tooltip kedua"));
  btn.addEventListener(MouseEvent.MOUSE_OUT, hlg);
  btn2.addEventListener(MouseEvent.MOUSE_OUT, hlg);
  function hlg(event:MouseEvent):void
  {
   Tooltip.Hide();
  }
  function tmpil(msg)
  { return function( e:MouseEvent ){
   Tooltip.Show(msg);
  }
  }
     */
    public class Tooltip 
    {
        static private var a:TextField;
        static private var b:String;
        static private var c:String;
        static private var d:Stage;
        static private var e:Boolean;
        
        static private var f:*;
        static private var g:Boolean;
        static private var h:Boolean;
        static private var i:uint;
        static private var j:MovieClip;
        static private var k:Boolean = false;
        static private var l:TextFormat;
        static private var m:uint;
        static private var n:String;
        static private var o:int;
        static private var p:Boolean;
        
        
        public function Tooltip():void
        {
           // constructor code
   
   trace("@Author  :: Ricko Nada ");
   trace("@website :: PustakaFlash.com ");
        }
        
        //************CONFIGURE METHODS*****************//
        
        public static function set Parent(value:MovieClip):void
        {
            j = value;
            k = true;
        }
        public static function get Parent():MovieClip
        {
            return j;
        }
        
        public static function SetupStage(projectStage):void
        {
            d = projectStage;
        }
        
        public static function ConfigureTooltip(hasBG:Boolean = true, hasBorder:Boolean = true, BGColor:uint = 0x666666):void
        {
            e = false;
            f = TextFieldAutoSize.LEFT;
            g = hasBG;
            h = hasBorder;
            i = BGColor;
            ResetTooltipTextField();
        }
        
        public static function ConfigureTextTooltip(color:uint = 0xFFFFFF, size:int = 10, underline:Boolean = false, font:String = "Verdana"):void
        {
            if(a == null) { return; }

            m = color;
            n = font;
            o = size;
            p = underline;
            
            l = new TextFormat();
            l.font = n;
            l.color = m;
            l.size = o;
            l.underline = p;
            a.defaultTextFormat = l;
            
        }
                
        //************PUBLIC METHODS*****************//
        public static function Show(texte:String = ""):void
        {
            if (e)
            {
                Hide();
            }
            
            ResetTooltipTextField();
            a.text = texte;
            if (a.textWidth > 200) 
            {
                a.width = 200;
            }
            else
            {
                a.width = a.textWidth + 10;
            }
            a.height = a.textHeight + 5;
            e = true;
            MoveTooltip();
            
            if (k)
            {
                if (j == null) { return; }
                j.addChild(a);
            }
            else
            {
                if (d == null) { return; }
                d.addChild(a);
            }
        }
        
        public static function Hide():void
        {
            if (k)
            {
                if (j == null) { return; }
                if (j.contains(a))
                {
                    j.removeChild(a);
                    e = false;
                }
            }
            else
            {
                if (d == null) { return; }
                if (d.contains(a))
                {
                    d.removeChild(a);
                    e = false;
                }
            }
            
        }
        
        public static function Invalidate():void
        {
            ResetTooltipTextField();
            ResetTextFormat();
            if (e)
            {
                Show();
            }
        }
        
        public static function set BackgroundColor(value:uint):void
        {
            i = value;
        }
        public static function get BackgroundColor():uint
        {
            return i;
        }
        public static function set Align(value:String):void
        {
            f = value;
        }
        public static function get Align():String
        {
            return f;
        }
        public static function set HasBackgroundColor(value:Boolean):void
        {
            g = value;
        }
        public static function get HasBackgroundColor():Boolean
        {
            return g;
        }
        public static function set HasBorder(value:Boolean):void
        {
            h = value;
        }
        public static function get HasBorder():Boolean
        {
            return h;
        }
        public static function set TextColor(value:uint):void
        {
            m = value;
        }
        public static function get TextColor():uint
        {
            return m;
        }
        public static function set Font(value:String):void
        {
            n = value;
        }
        public static function get Font():String
        {
            return n;
        }
        public static function set TextSize(value:int):void
        {
            o = value;
        }
        public static function get TextSize():int
        {
            return o;
        }
        public static function set IsUnderline(value:Boolean):void
        {
            p = value;
        }
        public static function get IsUnderline():Boolean
        {
            return p;
        }
        public static function set UseParent(value:Boolean):void
        {
            k = value;
        }
        public static function get UseParent():Boolean
        {
            return k;
        }
        
              //************PRIVATE METHODS*****************//
        static public function MoveTooltip():void
        {
            if (e == false) { return; }
            
            var h:int = a.height;
            var myPositions:Array = GetPosition();
            var myX:int = 0;
            var myY:int = 0;
            if(myPositions[0] == "left")
            {
                myX = d.mouseX - a.width - 10;
            }
            else
            {
                myX = d.mouseX + 40;
            }
            if(myPositions[1] == "up")
            {
                myY = d.mouseY - a.height;
            }
            else
            {
                myY = d.mouseY;
            }
            if((myY + a.height) > d.height)
            {
                var diff:int = (myY + a.height) - d.stageHeight;
                myY -= diff;
            }
            a.x = myX;
            a.y = myY;
        }
        
        private static function GetPosition():Array
        {
            var myX:int = d.mouseX;
            var myY:int = d.mouseY;
            
            var stageW:int = d.stageWidth;
            var stageH:int = d.stageHeight;
            
            if(myX < (stageW/2))
            {
                b = "right";
            }
            else
            {
                b = "left";
            }
            if(myY < (stageH/2))
            {
                c = "bottom";
            }
            else
            {
                c = "top";
            }
            var myArray:Array = new Array(b, c);
            return myArray;    
        }
        private static function ResetTooltipTextField():void
        {
            a = new TextField();
            a.autoSize = f;
            a.background = g;
            a.border = h;
            a.backgroundColor = i;
            a.selectable = false;
            a.wordWrap = true;
        }
        
        static private function ResetTextFormat():void
        {
            l = new TextFormat();
            l.font = n;
            l.color = m;
            l.size = o;
            l.underline = p;
            a.defaultTextFormat = l;
        }
    }
}