开发者

Flex easy set buttonmode to all buttons

开发者 https://www.devze.com 2023-02-06 20:52 出处:网络
is 开发者_开发技巧there an easy way to set the buttonMode to true to all my buttons in my application?

is 开发者_开发技巧there an easy way to set the buttonMode to true to all my buttons in my application? I thought to create a custom component which extends the s:Button and set there buttonMode to true but I wonder if there is an easier way like with CSS.

Thanks in advance


As Wade said, the skin is a good way to go. While setting buttomMode="true" on the skin won't work the way you want, you can set the host button's buttonMode from the skin like so:

<fx:Script>
    <![CDATA[
        import spark.components.Button;

        override protected function commitProperties():void
        {
            super.commitProperties();
            hostComponent.buttonMode = true;
        }

    ]]>
</fx:Script>


You may be able to do this with a skin and css. Copy the default ButtonSkin to a custom skin class and set buttonMode="true" on the skin. (If that doesn't work you can try to set hostComponent.buttonMode = true on creation complete.) Then set the skin for s:Button to your custom skin in your css.


You could either try writing a crawler which would walk through all your object at runtime, or something like this:

stage.addEventListener(Event.ADDED_TO_STAGE, parseItem, true);

and then:

function parseItem(e:Event):void{
  if (e.target is Button)
      e.target.buttonMode = true;
}

Each item which is added to the stage should go through this event (even if only its parent is added to the display list).

Of course you'll have to add this event listener before anything is added to the stage actually!


Unfortunately, I don't think you have any other option that creating a custom Button.

You could monkey patch the original Button component but I wouldn't recommand this pratice.


I would also suggest Maurycy's approach or you could just monkey patch the Button class in your project. That might even be easier and it would not cause a performance hit.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号