Search Flex Components Free

Custom Search

July 6, 2009

flex html tooltip component

Flex components accepts plain text to display as ToolTip. So there is no way to format the ToolTip text. So i looked into this problem, i checked the source code of the class “ToolTip”. There i got a very easy solution for this.

The ToolTip class object uses IUITextField object to display the ToolTip text. In component lifeCycle, at the process of commitProperties() method, text property of the IUITextField is get assigned by the String which is specified to for component’s tooltip property. I got the right place, The Trick is just instead of assigning the tooltip string to the text property, override it by the property htmlTextproperty of the IUITextField object, which will enable the html text to appear in tooltip.

So i created a  component HTMLToolTip, which overrides the protected function commitProperties()method of the TootTip object. here is the source code of the component;

  1. package com  
  2. {  
  3.     import mx.containers.*;  
  4.     import mx.controls.Text;  
  5.     import mx.controls.ToolTip;  
  6.     import mx.core.*;  
  8.     public class HTMLToolTip extends ToolTip  
  9.     {  
  10.         public function HTMLToolTip()  
  11.         {    super(); }  
  13.         override protected function commitProperties():void{  
  14.             super.commitProperties();  
  15.             textField.htmlText = text;  
  16.         }  
  17.     }  
  18. }  

To use this component, after loading the application (creationComplete()) useToolTipManager.toolTipClass to assign this component as toolTip custom class, and asign the components toolTip property to assign html text. here is sample code;

  2.     import com.*; 
  3.     private function init():void{ 
  4.         ToolTipManager.toolTipClass = HTMLToolTip; 
  5.         mtBtn.toolTip = "this is HTMLToolTip." 
  6.     } 
  7. ]]>  

The trick is overriding the components commitProperties() method.

Related Flex Tutorials