views:

23

answers:

1

I am trying to cancel a tooltip event (I only want it to display when the mouse is hovered over a certain area), and can't seem to figure it out. I tried stopPropagation, preventDefault, and stopImmediatePropagation, but none of them seem to work.

Here the code I am using:

        private function toolTipCreateHandler(event:ToolTipEvent):void {
            if(event.currentTarget.mouseX < 130) {
                var tooltip:PhotoToolTip = new PhotoToolTip();
                tooltip.src = event.currentTarget.toolTip;
                event.toolTip = tooltip;
            }
            else {
                event.stopImmediatePropagation();
            }
        }   

Any ideas?

Thanks

A: 

Step one, add an event listener to detect when the mouse leaves the area you want the tooltip, run a function and title it something like "toolTipDestroyer"

Step two, You need to call the destroy method of the tooltip manager

private function toolTipDestroyer():void {
    if (myToolTip) {
        ToolTipManager.destroyToolTip(myToolTip);
        myToolTip= null;
    }
}

Also, just for readability, give your tooltip some other name than "tooltip", you'll find it easier to follow up on your code later. My example names it "myToolTip"

invertedSpear
For my case, I think it would make the most sense to just call destroyToolTip toolTipCreateHandler function, as I don't want it display at all if it is not within the region specified. The issue here is that events on tied to a textArea, and as a result, the mouseOut won't suffice.
gmoniey
If that works go for it. I admit that I didn't test it, it just seemed to me like it wouldn't work in Flex since there isn't an OnHover event.
invertedSpear
turns out that didn't work. The problem is if that the user hasn't hovered over the correct area yet, the tooltip instance is null.
gmoniey