Flex 4 按钮皮肤禁用 alpha 设置被忽略?

发布于 2024-12-15 16:10:28 字数 3014 浏览 0 评论 0原文

我尝试为 Spark 按钮构建 Flex 4 皮肤,这是典型的做法。我根据自己的喜好调整了颜色和其他样式,包括使用点选择器来指定不同状态下的替代颜色等。然而,当按钮被禁用时,这些都会被忽略。无论我做什么,在禁用状态下,我的按钮总是有错误的颜色,并且 alpha 为 0.5(即使我特别声明 alpha.disabled="1")。所有其他皮肤状态均按预期工作。这是怎么回事?

这是我的定制皮肤。如果工作正常,它看起来没有阴影或高光,并且是渐变灰色。相反,它显示为 up 状态的 50% alpha 版本(闪亮的绿色)。

<?xml version="1.0" encoding="utf-8"?>
<s:SparkButtonSkin xmlns:fx="http://ns.adobe.com/mxml/2009" 
             xmlns:s="library://ns.adobe.com/flex/spark" 
             xmlns:fb="http://ns.adobe.com/flashbuilder/2009"
             minWidth="21" minHeight="21" alpha.disabled="1">

    <fx:Metadata>
        <![CDATA[ 
            [HostComponent("spark.components.Button")]
        ]]>
    </fx:Metadata>

    <s:states>
        <s:State name="up" />
        <s:State name="over" />
        <s:State name="down" />
        <s:State name="disabled" />
    </s:states>

    <s:Rect id="backgroundAndShadow" left="0" right="0" top="0" bottom="0" radiusX="5" radiusY="5">
        <s:filters>
            <s:DropShadowFilter blurX="5" blurY="5" blurX.down="3" blurY.down="3" alpha="0.5" distance="1" distance.down="0" angle="90" excludeFrom="disabled" />
        </s:filters>
        <s:fill>
            <s:LinearGradient rotation="90">
                <s:GradientEntry color.up="#00AD00" color="#007A00" color.disabled="#cccccc" />
                <s:GradientEntry color.up="#29FF29" color="#00F500" color.disabled="#bbbbbb" />
            </s:LinearGradient>
        </s:fill>
    </s:Rect>

    <s:Rect id="highlight" left="1" right="1" top="1" height="50%" topLeftRadiusX="4" topLeftRadiusY="4" topRightRadiusX="4" topRightRadiusY="4" excludeFrom="disabled">
        <s:fill>
            <s:LinearGradient rotation="90">
                <s:GradientEntry color="#ffffff" alpha="0.8" />
                <s:GradientEntry color="#ffffff" alpha="0.3" />
            </s:LinearGradient>
        </s:fill>
    </s:Rect>

    <s:Label id="labelDisplay"
             textAlign="center"
             horizontalCenter="0" verticalCenter="1" verticalAlign="middle"
             color="#ffffff" color.disabled="#555555"
             fontWeight="bold"
             left="2" right="2" top="2" bottom="2">

        <s:filters>
            <s:DropShadowFilter blurX="3" blurY="3" alpha="0.5" distance="1" distance.down="0" angle="90" excludeFrom="disabled" />
        </s:filters>
    </s:Label>

</s:SparkButtonSkin>

我还使用 Flash Builder 的皮肤创建向导/对话框自动生成按钮皮肤来完成此操作。即使这样,在禁用模式下专门将 alpha 设置为 1 也没有效果。

编辑
这是用于创建然后禁用按钮的代码:

_action1Button = new Action1Button();
view.actionGroup.addElement(_action1Button);
_action1Button.enabled = false;

错误是 _action1Button 不是实际的按钮,而是按钮的容器。哎哟!将其切换为 _action1Button.actionButton.enabled = false; 解决了该问题。

I attempted to build a Flex 4 skin for a Spark button, typical practice. I adjusted the colors and other styles to my liking, including using dot selectors to specify alternate colors and such during different states. However, these are all ignored when the button is disabled. Regardless of what I do, in the disabled state, my button always has the wrong color and is alpha'd to 0.5 (even if I specifically state that alpha.disabled="1"). All the other skin states work as expected. What is going on here?

This is my custom skin. If it were working correctly, it would appear to have no shadow or highlight, and would be a gradient grey color. Instead, it appears as a 50% alpha version of the up state (shiny green).

<?xml version="1.0" encoding="utf-8"?>
<s:SparkButtonSkin xmlns:fx="http://ns.adobe.com/mxml/2009" 
             xmlns:s="library://ns.adobe.com/flex/spark" 
             xmlns:fb="http://ns.adobe.com/flashbuilder/2009"
             minWidth="21" minHeight="21" alpha.disabled="1">

    <fx:Metadata>
        <![CDATA[ 
            [HostComponent("spark.components.Button")]
        ]]>
    </fx:Metadata>

    <s:states>
        <s:State name="up" />
        <s:State name="over" />
        <s:State name="down" />
        <s:State name="disabled" />
    </s:states>

    <s:Rect id="backgroundAndShadow" left="0" right="0" top="0" bottom="0" radiusX="5" radiusY="5">
        <s:filters>
            <s:DropShadowFilter blurX="5" blurY="5" blurX.down="3" blurY.down="3" alpha="0.5" distance="1" distance.down="0" angle="90" excludeFrom="disabled" />
        </s:filters>
        <s:fill>
            <s:LinearGradient rotation="90">
                <s:GradientEntry color.up="#00AD00" color="#007A00" color.disabled="#cccccc" />
                <s:GradientEntry color.up="#29FF29" color="#00F500" color.disabled="#bbbbbb" />
            </s:LinearGradient>
        </s:fill>
    </s:Rect>

    <s:Rect id="highlight" left="1" right="1" top="1" height="50%" topLeftRadiusX="4" topLeftRadiusY="4" topRightRadiusX="4" topRightRadiusY="4" excludeFrom="disabled">
        <s:fill>
            <s:LinearGradient rotation="90">
                <s:GradientEntry color="#ffffff" alpha="0.8" />
                <s:GradientEntry color="#ffffff" alpha="0.3" />
            </s:LinearGradient>
        </s:fill>
    </s:Rect>

    <s:Label id="labelDisplay"
             textAlign="center"
             horizontalCenter="0" verticalCenter="1" verticalAlign="middle"
             color="#ffffff" color.disabled="#555555"
             fontWeight="bold"
             left="2" right="2" top="2" bottom="2">

        <s:filters>
            <s:DropShadowFilter blurX="3" blurY="3" alpha="0.5" distance="1" distance.down="0" angle="90" excludeFrom="disabled" />
        </s:filters>
    </s:Label>

</s:SparkButtonSkin>

I also did this with an automatically generated skin for the Button using Flash Builder's skin creation wizard/dialog. Even then, specifically setting the alpha to 1 in disabled mode had no effect.

Edit
This is the code used to create and then disable the button:

_action1Button = new Action1Button();
view.actionGroup.addElement(_action1Button);
_action1Button.enabled = false;

The error was that _action1Button is not the actual button, rather, it's the container of the button. Doh! Switching it to _action1Button.actionButton.enabled = false; fixed the issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

还给你自由 2024-12-22 16:10:29

你的皮肤很适合我。我在启用状态下得到一个绿色按钮,然后在启用时得到一个没有阴影的灰色渐变为 false。我像这样测试了它(其中 TestSkin 是上面发布的您的皮肤):

<s:Button skinClass="TestSkin" enabled="false" />

我认为问题与您使用皮肤的方式有关。您可以发布定义按钮本身的代码吗?

Your skin works fine for me. I get a green button in the enabled state then a grey gradient without drop shadow when enabled is false. I tested it like this (where TestSkin is your skin posted above):

<s:Button skinClass="TestSkin" enabled="false" />

I assume the problem has to do with how you are using the skin. Can you post the code where the button itself is defined?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文