Feb 26 2008

Custom Flex ToolTips made easy with CustomToolTip

Posted by Joe Rinehart at 7:30 AM
6 comments
- Categories: Flex

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.

Comments

Rachel Maxim

Rachel Maxim wrote on 02/26/08 9:56 AM

Nice work - I can't wait to try this out!
Joe Rinehart

Joe Rinehart wrote on 02/26/08 10:19 AM

Thanks Rachel....I almost want to rename it CustomToolTipHelper, because stating that it is the tooltip is a bit misleading.

Let me know if it gives you any grief. As it's an AS3 class, you need to put the CustomToolTip tag before visual children, in the same place you'd put Validators, etc.
Brian Holmes

Brian Holmes wrote on 02/26/08 11:48 AM

Not sure what if i set it up wrong, but I can't get your example to create an example of my custom class. All that happens is that i get the tooltip text that you had placed on your example: &quot;someTooltipText&quot;. I dropped all your code in. Any ideas why it might not create an instance of the class i'm passing in?
Brian Holmes

Brian Holmes wrote on 02/26/08 12:01 PM

Ah, you still have to implement IToolTip in your custom tool tip.
Demian

Demian wrote on 03/03/08 4:19 PM

Thanks for the great work. However, I'm having an issue using your sample. I must be missing something simple. No matter what I do, I get the following error: &quot;Could not resolve &lt;tooltip:CustomToolTip&gt; to a component implementation.&quot;

I've tried put an import com.firemoss.controls.tooltip in my script, and I have xnlns:tooltip=&quot;com.firemoss.controls.tooltip&quot; in my root level tag. What am I missing?

Thanks!
Magda

Magda wrote on 09/29/08 3:28 AM

Let me know if it gives you any grief. As it's an AS3 class, you need to put the CustomToolTip tag before visual children, in the same place you'd put Validators, etc.
http://www.batteryfast.co.uk/clevo/m375.php clevo m375 m360 M300N M310N laptop battery,
http://www.batteryfast.co.uk/clevo/dr202.php clevo dr202 me202bb laptop battery,
http://www.batteryfast.co.uk/fujitsu/s2000.php fujitsu fpcbp64 s2000 s2010 s2020 laptop battery,
http://www.batteryfast.co.uk/fujitsu/cbp109.php fujitsu fucbp109 S7011 S7021 S7025 laptop battery,
http://www.batteryfast.co.uk/fujitsu/fpcbp49.php fujitsu fpcbp49 P1000 P2000 laptop battery,
http://www.batteryfast.co.uk/uniwill/un255.php uniwill 255-3S4400-G1L1 un255 laptop battery,

http://www.batteryfast.co.uk/uniwill/un258.php uniwill Amilo A-1630 A1630 UN258 laptop battery,
http://www.batteryfast.co.uk/uniwill/un755.php uniwill 755-4S4000-S1P1 un755 laptop battery,
http://www.batteryfast.co.uk/uniwill/un243.php uniwill BAT-243S1 UN243 laptop battery,
http://www.batteryfast.co.uk/uniwill/un223.php uniwill un233 laptop battery,
http://www.batteryfast.co.uk/apple/A1175.php apple A1175 Macbook Pro 15-4 laptop battery,
http://www.batteryfast.co.uk/asus/m3000-2.php Battery For ASUS M3 M3N M3NP M3000 M3000N M3000NP 4S2P black laptop battery,

http://www.batteryfast.co.uk/asus/m6-2.php asus a42-m6 m6n m67 m68n m6000 laptop battery,
http://www.batteryfast.co.uk/asus/a42-w1.php asus W1 W1000 A42-W1 W1G W1Ga laptop battery,
http://www.batteryfast.co.uk/asus/a31-s5-2.php ASUS A31-S5 A32-S5 S52N S5000 S5200N S5N laptop battery,
http://www.batteryfast.co.uk/mitac/8375-2.php MITAC 8175 8375 8575 8575A 8575P LAPTOP BATTERY black laptop battery,
http://www.batteryfast.co.uk/toshiba/pa3176u-1bas-2.php Battery For Toshiba Portege M200 M205 PA3128U PA3191U black laptop battery,
http://www.batteryfast.co.uk/acer/batcl32l.php acer aspire batcl32l 2000 batcl32 2001 2003 laptop battery,

Write your comment



(it will not be displayed)