Alex Rivera | Logout

how to show a tooltip on a disabled control?

Asked 2010-05-26T15:05:03.187
9

I'm displaying a list of buttons, some of which might be disabled. I need to show a tooltip on the disabled buttons with an explanation of why it's disabled, but it seems I can't disable the button without disabling the tooltip. Is there a simple way around this?

Edit
Report

1 Answer

1

One way to do this is to override the enabled getter and setter to do what you want. So in my case, I still wanted most mouse events to fire, just not the click event.

<?xml version="1.0" encoding="utf-8"?>
<s:Button buttonMode="true" click="handleClick(event)" xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:s="library://ns.adobe.com/flex/spark">
    <fx:Script>
        <![CDATA[
            public var data:Object;
            private var _enabled:Boolean = true;

            public override function get enabled():Boolean
            {
                return _enabled;
            }

            public override function set enabled(value:Boolean):void
            {
                _enabled = value;
                invalidateDisplayList();
                dispatchEvent(new Event("enabledChanged"));
                invalidateSkinState();
            }

            protected function handleClick(event:MouseEvent):void
            {
                if (!_enabled)
                {
                    event.stopPropagation();
                }
            }
        ]]>
    </fx:Script>
</s:Button>

Since mouse events now fire, the tooltips work again.

answered 2013-06-18T19:59:41.470

Your Answer