Mailing List
Home
Flash Pro
Extending Flash
Flash Macromedia Developer
Subjects
Firework Effect
setInterval bug identified and fixed
setInterval bug identified and fixed
ScrollPane component doesn 't auto update
Help: MX 2004 How to script a print button to print the entire sli
Event Dispatcher between classes
memory management removeMovieClip /
MX2004 Dataset itemClassName
Order of events per frame
XML to Object help
Textfield prototype question
Flash and QuickTime VR
Reading and displaying RSS feeds in Flash MX
Flash MX 2004 Sucks
AW: [Flashcoders] Switch/Case vs If/else
AW: [Flashcoders] Switch/Case vs If/else
Flash Interface with 10mb xml file
Web Service Results
Listener Object 's best practice
 
Search:  
Power your search with and, or, +, -, or "some phrase" operators.
Tooltip

Tooltip

2004-02-17       - By 1stPIXEL

 Back
Reply:     1     2     3     4     5     6     7  

Here 's what i 've done:

(most credits go to Mario Klingemann)


class ToolTip extends MovieClip {
   private var $registeredClips:Array = [];
   private var $animated:Boolean = true;
   private var $animTime:Number = 350;
   private var $animID:Number;
   private var $tiptext:String = " ";
   private var $fmt:TextFormat;
   private var $depth:Number = 0;
   private var $tt:MovieClip;
   private var $bgColor:Number;
   //
   function ToolTip () {
      $bgColor = 0xFFFFCC;
   }
   // ###########################################################################################
   public function registerClip (clip:MovieClip, tiptext:String) {
      $registeredClips.push ([clip, tiptext]);
   };
   public function showToolTip (clip:MovieClip) {
      if ($animID != undefined) clearAnimation ();
      var i = 0, len = $registeredClips.length;
      while (i < len) {
         if ($registeredClips[i][0] == clip) {
            $tiptext = $registeredClips[i][1];
            var size = calcSize ($tiptext);
            drawTip ($registeredClips[i][0], size[0], size[1]);
            return;
         }
         i++;
      }
   };
   public function hideToolTip () {
      clearAnimation();
      $animID = setInterval (this, "fadeOut ", 1);
   };
   // ###########################################################################################
   private function removeClip (clip:MovieClip) {
      var i = 0, len = $registeredClips.length;
      while (i < len) {
         if ($registeredClips[i][0] == clip) $registeredClips.splice (i, 0);
         i++;
      }
   };
   private function calcSize (txt:String) {
      $fmt = new TextFormat ();
      $fmt.font = "__TMS ";
      $fmt.size = 12;
      // getTextExtent returns: width, height, ascent, descent, textFieldHeight, textFieldWidth.
      var obj = $fmt.getTextExtent (txt);
      var w = obj.textFieldWidth + 2;
      var h = obj.textFieldHeight + 2;
      return ([w, h]);
   };
   private function blurredRect (clip, x, y, width, height, blur, color, alpha) {
      clip.lineStyle();
      var f = [];
      var sum = 0;
      for (var i = 1; i <blur+1; i++) {
         f[i-1] = i*i;
         sum += f[i-1];
      }
      var newfactor= 2;
      var counter = 40;
      var factor;
      do {
         factor=newfactor
         var b = 0;
         for (var i = 0; i <=blur; i++) {
            var ftemp = (f[i]*(factor*alpha)/sum)/100;
            b = b*(1-ftemp)+ftemp;
         }
         counter--;
         newfactor *= alpha/(100*b);
      } while ((counter >0) && (Math.abs(100*b-alpha) >.5));
      for (var i = 0; i <=blur; i++) {
         f[i] *= (factor*alpha)/sum;
      }
      for (var i = 0; i <=blur; i++) {
         clip.beginFill(color, f[i]);
         roundRect(clip, 1+(x+i)-blur/2, 1+(y+i)-blur/2, x+width-i+blur/2-1, y+height-i+blur/2-1, blur-(i*2/3));
         clip.endFill();
      }
   };
   private function roundRect (clip, x1, y1, x2, y2, r) {
      r = Math.min(Math.abs(r), Math.min(Math.abs(x1-x2), Math.abs(y1-y2))/2);
      var f = 0.707106781186548*r;
      var a = 0.588186525863094*r;
      var b = 0.00579432557070009*r;
      var ux = Math.min(x1, x2);
      var uy = Math.min(y1, y2);
      var lx = Math.max(x1, x2);
      var ly = Math.max(y1, y2);
      clip.moveTo(ux+r, uy);
      var cx = lx-r;
      var cy = uy+r;
      clip.lineTo(cx, uy);
      clip.curveTo(lx-a, uy+b, cx+f, cy-f);
      clip.curveTo(lx-b, uy+a, lx, uy+r);
      cy = ly-r;
      clip.lineTo(lx, cy);
      clip.curveTo(lx-b, ly-a, cx+f, cy+f);
      clip.curveTo(lx-a, ly-b, lx-r, ly);
      cx = ux+r;
      clip.lineTo(cx, ly);
      clip.curveTo(ux+a, ly-b, cx-f, cy+f);
      clip.curveTo(ux-b, ly-a, ux, ly-r);
      cy = uy+r;
      clip.lineTo(ux, cy);
      clip.curveTo(ux+b, uy+a, cx-f, cy-f);
      clip.curveTo(ux+a, uy+b, ux+r, uy);
   };
   private function drawTip (ref:MovieClip, w:Number, h:Number) {
      if ($depth != undefined) _root[ "__TOOLTIP "].removeMovieClip();
      $depth = _root.getNextHighestDepth ();
      $tt = _root.createEmptyMovieClip ( "__TOOLTIP ", $depth);
      $tt._alpha = 0;
      var rect = $tt.createEmptyMovieClip ( "rect ", 1);
      rect.lineStyle (0, 0x0, 0);
      rect.beginFill ($bgColor, 100);
      with (rect) {
         lineTo (w, 0);
         lineTo (w, h);
         lineTo (0, h);
         lineTo (0, 0);
         endFill ();
      }
      $tt.createTextField ( "tiptxt ", 2, 0, 0, w, h);
      if ($bgColor == 0x0) $tt.tiptext.textColor = 0xFFFFF;
      $tt.tiptxt.text = $tiptext;
      $tt.tiptxt.background = false;
      $tt.tiptxt.border = false;
      $tt.tiptxt.selectable = false;
      $tt.tiptxt.embedFonts = true;
      $tt.tiptxt.multiline = true;
      $tt.tiptxt.setTextFormat ($fmt);
      var shadow = $tt.createEmptyMovieClip ( "shadow ", 0);
      blurredRect(shadow, 0, 0, w+3, h+3, 6, 0x0, 45);
      positionTip()
      if ($animated) {
         $animID = setInterval (this, "fadeIn ", 1);
      } else {
         $tt._alpha = 100;
      }
   };
   private function positionTip () {
      $tt._x = _root._xmouse + 5;
      $tt._y = _root._ymouse + 5;
   }
   private function fadeIn () {
      if ($tt._alpha >= 100) {
         clearInterval ($animID);
         delete ($animID);
      } else {
         $tt._alpha += 2;
      }
   }
   private function clearAnimation () {
      clearInterval ($animID);
      delete ($animID);
   }
   private function fadeOut () {
      if ($tt._alpha <= 0) {
         clearInterval ($animID);
         delete ($animID);
         _root[ "__TOOLTIP "].removeMovieClip();
      } else {
         $tt._alpha -= 5;
      }
   }
};

simple use: (clip instance 'button ' should be on Stage ;-) )

import ToolTip;
_global.toolTip = new ToolTip();
button.onRollOver = function () {
   toolTip.showToolTip(this)
};
button.onRollOut = function () {
   toolTip.hideToolTip(this)
};
toolTip.registerClip (button, "Hallo, \rich bin nur ein kleiner unscheinbarer Knopf, \rder einen Tooltip besitzt. ");


=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
Supported by Fig Leaf Software
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
Be sure to check the archives and the wiki:
http://chattyfig.figleaf.com/
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
http://chattyfig.figleaf.com/cgi-bin/ezmlm-cgi?1:mss:104495
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
To unsubscribe send a blank e-mail to:
Normal Mode: flashcoders-unsubscribe@(protected)
Digest Mode: flashcoders-digest-unsubscrive@(protected)