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 htmlText property 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;
package com
{
import mx.containers.*;
import mx.controls.Text;
import mx.controls.ToolTip;
import mx.core.*;
public class HTMLToolTip extends ToolTip
{
public function HTMLToolTip()
{ super(); }
override protected function commitProperties():void{
super.commitProperties();
textField.htmlText = text;
}
}
}
To use this component, after loading the application (creationComplete()) use ToolTipManager.toolTipClass to assign this component as toolTip custom class, and asign the components toolTip property to assign html text. here is sample code;
<![CDATA[
import com.*;
private function init():void{
ToolTipManager.toolTipClass = HTMLToolTip;
mtBtn.toolTip = "this is <strong>HTML</strong>Tool<strong>Tip."
}
]]>
The trick is overriding the components commitProperties() method.

thanks, this is a very neat solution which makes tooltips much more useful.
Very clean solution; thanks for the tip!
This totally just solved a problem I was having – thanks so much!
This was really very useful, thanks a lot!!!!
beautiful solution. thank you.
I am using Flex 3.
ToolTipManager.toolTipClass = HTMLToolTip; — this line does not compile for me.
1120: Access of undefined property HTMLToolTip.
Sorry Guys, Its my mistake.
” The above code works perfectly. “
hey harry potter
why don’t you say how did you solve it?
So, I bring you a soluiton:
rename HTMLToolTip to ToolTipHTML
and it works
btw,
thx
Very useful!
Thank you!
Very nice solution, the only potential problem I can see if that the change looks global. You can’t change the tooltip class for just one screen of your application. Additionally Flex libraries can’t use this solution without potentially unexpected ramifications in their calling applications.
Hi,
I would like to develop a tooltip which will have “more info” link. Do you have any neat idea for this?
So I should me able to move mouse over the tooltip and click on “more info” which will give a popup with extended information.
–
Alex
good job! Thanks
If the default font is embedded one, then the htmlText is not working. Can anybody please help on this?
Nice, very useful.
Hi, thanks so much. it was useful.
thanks heaps for this!
The solution look bery clean and simple…But this doesn’t work when you use it with creating a ToolTip in Actionscript and assigning the dynamic text.
I have done something like this..
In below in hitData.displayText I will get html text but when I assign it I could see html chars also in my tooltip.
I have also assigned the toolTip class in creationComplete() as below but no luck..
ToolTipManager.toolTipClass = HTMLToolTip;
private var myToolTip:ToolTip;
private function showToolTip(event:ChartItemEvent):void
{
var hitData:HitData = event.hitData;
var globalPoint:Point = new Point(event.localX,event.localY);
globalPoint = pieChart.localToGlobal(globalPoint);
// Create a simple tooltip that appears at the mouse x and y position
if(!myToolTip)
{
myToolTip = ToolTipManager.createToolTip(“”, -100, -100,”errorTipAbove”) as ToolTip;
}
var colorCode:String = “#” + hitData.contextColor.toString(16);
myToolTip.text = hitData.displayText;
myToolTip.setStyle(“color”,”#000000″);
myToolTip.setStyle(“borderColor”, colorCode);
myToolTip.move(globalPoint.x+10,globalPoint.y+10);
}
Does any one know solution for this..??
Thanks in advance!!!
Very nice solution. Thak you very much.
I did not check this within the Actionscript.
Excelente solucion, muchas gracias.