Hello: I’m working on some tooltip code which displays a tooltip when the user clicks on an HTML text link. Right now, the tooltip fades out as soon as the user moves the mouse, but I think it would be better to build in a short delay of about half a second. I tried to add some Timer class code but I just made a mess of things, so I’m wondering if someone else can figure out how to add that in.
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;
var glossaryToolTip:Sprite;
var toolTipVisible:Boolean = false;
var roundedRect:Sprite;
var stroke:Sprite;
var alphaTween:Tween;
var tooltipFormat:TextFormat;
var linkText:TextField = new TextField();
linkText.width = 350;
linkText.selectable = false;
linkText.multiline = true;
linkText.wordWrap = true;
linkText.autoSize = TextFieldAutoSize.LEFT;
linkText.htmlText = "The bailout is designed to allow GM and Chrysler to avert threatened bankruptcy through March with short-term loans. <font color='#C1C035'><b><u><a href='event:Link Clicked'>Ford Motor Co</a></u></b></font> is not requesting immediate help but would like a line of credit in case its finances worsen.";
addChild(linkText);
linkText.addEventListener(TextEvent.LINK, linkEvent);
linkText.addEventListener(MouseEvent.MOUSE_MOVE, mouseMove);// was MOUSE_OUT
function linkEvent(event:TextEvent):void {
if (!toolTipVisible) {
glossaryToolTip = new Sprite();
glossaryToolTip.x = mouseX+12;
glossaryToolTip.y = mouseY+10;
glossaryToolTip.mouseChildren = false;
glossaryToolTip.mouseEnabled = false;
addChild(glossaryToolTip);
var tField:TextField = new TextField;
tField.name = "tooltip_tb";
tField.x = 12;
tField.y = 15;
tField.width = 330;
tField.background = true;
tField.backgroundColor = 0xF5F5DC;
tField.selectable = false;
tField.multiline = true;
tField.wordWrap = true;
tField.condenseWhite = true;// Needed for proper display of HTML text
tField.antiAliasType = AntiAliasType.NORMAL;
tField.autoSize = TextFieldAutoSize.LEFT;
tField.htmlText = "<b>Ford Motor Company</b><br>Ford Motor Company is an American multinational corporation and the world's fourth largest automaker based on worldwide vehicle sales, following Toyota, General Motors, and Volkswagen.";
glossaryToolTip.addChild(tField);
addEventListener(Event.ENTER_FRAME, moveTool);
toolTipVisible = true;
}
}
function mouseMove(e:MouseEvent):void {
removeEventListener(Event.ENTER_FRAME, moveTool);
if (toolTipVisible) {
alphaTween = new Tween(glossaryToolTip, "alpha", Regular.easeOut, 1, 0, 0.20, true);
alphaTween.addEventListener(TweenEvent.MOTION_FINISH, removeToolTip);
function removeToolTip():void {
removeChild(glossaryToolTip);
}
toolTipVisible = false;
}
}
function moveTool(e:Event):void {
glossaryToolTip.x = mouseX+12;
glossaryToolTip.y = mouseY+10;
}
Sample file:
http://www.tornedgedesign.com/_test/kirupa/tooltip.zip