Turadg
Turadg

Reputation: 7681

How to remove hover / rollOver effects globally on Spark components?

My goal is to remove all hover feedback from the UI. The motivation is for testing touch interface prototypes and not wanting users to have the queue of interactivity when the mouse hovers which they won't have with a touch interface.

I have a partial solution but it has two problems:

  1. Requires an event handler on each component.
  2. Flickers on hover.

        protected function ui_suppressHover(event:MouseEvent):void
        {
            var b = event.currentTarget as UIComponent;
            b.skin.currentState = "up";
        }
    

    <s:Button x="118" y="60" label="Change em" click="button1_clickHandler(event)" rollOver="button1_rollOverHandler(event)" mouseOver="ui_suppressHover(event)"/>

Upvotes: 0

Views: 1380

Answers (2)

Turadg
Turadg

Reputation: 7681

Here's a partial solution spurred by Maxim's answer. You can make a HoverlessButton class by extending Button and overriding as so:

override protected function getCurrentSkinState():String
{               
    var state:String = super.getCurrentSkinState();
    if (state == "over")
        state = "up";
    return state;
}

You have to call the super impl first because it's the only one that can check properly for isDown(), which is private.

Upvotes: 1

Maxim Kachurovskiy
Maxim Kachurovskiy

Reputation: 3022

It's better to override getCurrentSkinState, e.g. see spark Button.as:

override protected function getCurrentSkinState():String
{
    if (!enabled)
        return "disabled";

    if (isDown())
        return "down";

    if (hovered || mouseCaptured)
        return "over";

    return "up";
}

So just remove hovered || mouseCaptured "if".

Upvotes: 2

Related Questions