Besi
Besi

Reputation: 22939

How to disable the icon on a Flex3 Button

I have a button which I use for sending a message. When the message text is empty, it should not be possible to click the button.

This is all fine and not an issue. The only thing that is bugging me is the fact that I can disable the send button but the image does not get disabled (like I would expect).

Is there a way to do this elegantly because I don't want to provide a sendicon_disabled.png and change it myself (I don't think this should be my job).

Upvotes: 1

Views: 651

Answers (1)

Constantiner
Constantiner

Reputation: 14221

You can use the following button for that:

package
{
    import mx.controls.Button;
    import mx.core.mx_internal;

    use namespace mx_internal;

    public class IconButton extends Button
    {
        private var enabledChanged:Boolean = false;

        override public function set enabled(value:Boolean):void
        {
            if (super.enabled == value)
            {
                return;
            }
            super.enabled = value;
            enabledChanged = true;
            invalidateDisplayList();
        }

        override protected function updateDisplayList(unscaledWidth:Number,
                                                      unscaledHeight:Number):void
        {
            super.updateDisplayList(unscaledWidth, unscaledHeight);
            if (enabledChanged)
            {
                if (!enabled && currentIcon)
                {
                    currentIcon.alpha = 0.5;
                }
                enabledChanged = false;
            }
        }
    }
}

You can use your custom alpha value or move it to separate style.

Upvotes: 3

Related Questions