Over the past year, I've spent a good deal of my time reconciling what designers create with what Flex provides. One of the items I run into most frequently is the need for a seriously custom tooltip: images, formatted fonts, etc.
Until today, my approach matched many others, handling the toolTipCreate event and setting the tooltip to use manually. This got a bit repetitive, so I've wrapped up the logic in a CustomToolTip class (attached to this blog entry, download it here) that makes it a declarative process.
You simply state the component creating the tooltip (the "source") and what class to use (not instance, but class!) as a ToolTip (the "renderer"):
<tooltip:CustomToolTip source="{someButton}" renderer="{com.myapp.SomeToolTip}" />
<mx:Button id="someButton" label="Some Button with a Custom Tooltip" toolTip="someTooltipText" />
When the button is moused over, a new instance of com.myapp.SomeToolTip will be created.
If your renderer class implements ICustomToolTip (in the attached .zip), it'll have the source's instance set into its "source" property. This allows you to place a custom tooltip on something like an itemRenderer and access its underlying "data" property.
6 comments - Posted by Joe Rinehart at 7:30 AM - Categories: Flex