<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tucker Watson&#187; ToolTips</title>
	<atom:link href="http://tuckwat.com/blog/tag/tooltips/feed/" rel="self" type="application/rss+xml" />
	<link>http://tuckwat.com/blog</link>
	<description>Software development - Flex, Niagara AX, oBIX, and more</description>
	<lastBuildDate>Fri, 18 Jun 2010 00:43:37 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Arrow ToolTips in Flex with Customized Color and Position</title>
		<link>http://tuckwat.com/blog/flex/arrow-tooltips-flex-customized-color-position/</link>
		<comments>http://tuckwat.com/blog/flex/arrow-tooltips-flex-customized-color-position/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 01:51:03 +0000</pubDate>
		<dc:creator>Tucker</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Component]]></category>
		<category><![CDATA[ToolTips]]></category>

		<guid isPermaLink="false">http://tuckwat.com/blog/?p=267</guid>
		<description><![CDATA[Flex doesn&#8217;t make it easy to customize your ToolTip&#8217;s positioning or look.  You can write your own ToolTip style and draw your own borders or you can use the &#8220;error tips&#8221; that already have arrows built in.
Manually creating and destroying tooltips
Rather than use the &#8216;toolTip&#8217; property of a component, we&#8217;re going to use the [...]]]></description>
			<content:encoded><![CDATA[<p>Flex doesn&#8217;t make it easy to customize your ToolTip&#8217;s positioning or look.  You can write your own <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=tooltips_6.html">ToolTip style and draw your own borders</a> or you can use the &#8220;error tips&#8221; that already have arrows built in.</p>
<h5 style="padding-top:5px;">Manually creating and destroying tooltips</h5>
<p>Rather than use the &#8216;toolTip&#8217; property of a component, we&#8217;re going to use the <a href="http://livedocs.adobe.com/flex/2/langref/mx/managers/ToolTipManager.html">ToolTipManager</a> to create and remove tooltips.  This method allows us to position tooltips anywhere on the stage, apply animations, and provide dynamic text.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> myToolTip<span style="color: #000000; font-weight: bold;">:</span>ToolTip;
&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> showToolTip<span style="color: #000000;">&#40;</span>evt<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span>, <span style="color: #004993;">text</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
   <span style="color: #009900;">// Create a simple tooltip that appears at the mouse x and y position</span>
   myToolTip = ToolTipManager.createToolTip<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Tooltip&quot;</span>, evt.<span style="color: #004993;">x</span>, evt.<span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> ToolTip;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #009900;">// Remove the tooltip</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> killToolTip<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
   ToolTipManager.destroyToolTip<span style="color: #000000;">&#40;</span>myToolTip<span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>To use the above functions, we need to assign them to a components <i>mouseOver</i> and <i>mouseOut</i> events:</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Button</span> label=<span style="color: #ff0000;">&quot;Button&quot;</span> mouseOver=<span style="color: #ff0000;">&quot;showToolTip(event)&quot;</span> mouseOut=<span style="color: #ff0000;">&quot;killToolTip()&quot;</span><span style="color: #7400FF;">/&gt;</span></span></pre></div></div>

<h5 style="padding-top:5px;">Adding arrows by using Flex&#8217;s &#8220;error tips&#8221;</h5>
<p>When creating tooltips by using &#8220;ToolTipManager.createToolTip(&#8230;)&#8221; you can pass in a 4th parameter as a string that specifices which error tip to use.  The available options are:</p>
<ul>
<li>&#8220;errorTipAbove&#8221;</li>
<li>&#8220;errorTipBelow&#8221;</li>
<li>&#8220;errorTipRight&#8221;</li>
</ul>
<p>Error tips default to a red background color and black text but you can easily change this through styles:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">myToolTip.<span style="color: #004993;">setStyle</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;borderColor&quot;</span>, <span style="color: #990000;">&quot;#ff6600&quot;</span><span style="color: #000000;">&#41;</span>;
myToolTip.<span style="color: #004993;">setStyle</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;color&quot;</span>, <span style="color: #990000;">&quot;white&quot;</span><span style="color: #000000;">&#41;</span>;</pre></div></div>

<h5 style="padding-top:5px;">Positioning tooltips above, below, and to the right</h5>
<p>Another pitfall when creating tooltips manually is specifying the position of the tooltip.  The &#8220;createToolTip&#8221; method requires the x and y coordinates passed in are &#8220;global&#8221; coordinates, rather than the local x and y coordinates within a container.  This makes it a little more tricky to place a tooltip directly below or to the right of a component.  The easiest way to fix this is using the method &#8220;contentToGlobal(point)&#8221;.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> pt<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Point</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Point</span><span style="color: #000000;">&#40;</span>evt.<span style="color: #004993;">currentTarget</span>.<span style="color: #004993;">x</span>, evt.<span style="color: #004993;">currentTarget</span>.<span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span>;
pt = evt.<span style="color: #004993;">currentTarget</span>.<span style="color: #004993;">parent</span>.contentToGlobal<span style="color: #000000;">&#40;</span>pt<span style="color: #000000;">&#41;</span>;</pre></div></div>

<h5 style="padding-top:8px;">Putting it all together (right click for source):</h5>
<div class="other">
<iframe style="border-style:solid;" src="http://www.tuckwat.com/blog/files/CustomTooltips/CustomTooltips.html" width="584" height="200"></iframe>
</div>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?&amp;linkurl=http%3A%2F%2Ftuckwat.com%2Fblog%2Fflex%2Farrow-tooltips-flex-customized-color-position%2F&amp;linkname=Arrow%20ToolTips%20in%20Flex%20with%20Customized%20Color%20and%20Position"><img src="http://tuckwat.com/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Save/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://tuckwat.com/blog/flex/arrow-tooltips-flex-customized-color-position/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
