September 17th, 2007 by Kyle
Tags: errortip-error-tip, Flex, tooltip, tooltipmanager, validate, vallidation
Posted in: ActionScript, Flex
Here is a simple little demo that shows how to create, style and position a tooltip so it looks like an Error bubble.
This way you can have more than one visible Error Tip visible at once.
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" styleName="plain" verticalAlign="middle" horizontalAlign="center">
<mx:Script>
<![CDATA[
import mx.controls.ToolTip;
import mx.managers.ToolTipManager;
private var errorTip:ToolTip;
private var myError:String;
private function validateEntryA(event:Object):void {
myError="Error A.";
errorTip = ToolTipManager.createToolTip(myError,event.currentTarget.x + event.currentTarget.width,event.currentTarget.y) as ToolTip;
errorTip.setStyle("styleName", "errorTip");
}
private function validateEntryB(event:Object):void {
myError="Error B.";
var pt:Point = new Point(event.currentTarget.x, event.currentTarget.y);
pt = event.currentTarget.contentToGlobal(pt);
errorTip = ToolTipManager.createToolTip(myError,pt.x + event.currentTarget.width,pt.y) as ToolTip;
errorTip.setStyle("styleName", "errorTip");
}
]]>
</mx:Script>
<mx:TextInput id="a" width="100" valueCommit="validateEntryA(event)"/>
<mx:VBox>
<mx:TextInput id="b" width="100" valueCommit="validateEntryB(event)"/>
</mx:VBox>
</mx:Application>
Hopefully this will be useful to some.
Here is a link to a Flex Builder 2.0.1 project (compiled with SDK hotfix2) containing a sample demonstrating the solution described above.
Tweet
4 Comments »

July 21st, 2008 at 1:13 pm
Ok, but how can i destroy all tooltips ?
If i used on the click event of a button :
if (errorTip)
ToolTipManager.destroyToolTip(errorTip)
Only the first is destroy and the second click return an error !
July 22nd, 2008 at 12:47 pm
http://blog.flexmonkeypatches.com/2007/10/04/flex-close-all-popups/
February 6th, 2009 at 7:36 am
July 20th, 2009 at 7:22 am
Yeah, but have you seen changing the container sizes at runtime could display the tooltips at different locations.