【问题标题】:Flex 4 button skin disabled alpha setting ignored?Flex 4 按钮皮肤禁用 alpha 设置被忽略?
【发布时间】:2011-12-29 01:57:38
【问题描述】:

我尝试为 Spark 按钮构建 Flex 4 皮肤,这是典型的做法。我根据自己的喜好调整了颜色和其他样式,包括在不同状态下使用点选择器指定替代颜色等。但是,当按钮被禁用时,这些都会被忽略。不管我做什么,在禁用状态下,我的按钮总是有错误的颜色并且是 alpha'd 到 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 的皮肤创建向导/对话框为 Button 自动生成了皮肤。即使这样,在禁用模式下专门将 alpha 设置为 1 也没有效果。

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

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

错误在于 _action1Button 不是实际的按钮,而是按钮的容器。嗬!将其切换到 _action1Button.actionButton.enabled = false; 解决了这个问题。

【问题讨论】:

    标签: apache-flex skinning flex-spark


    【解决方案1】:

    你的皮肤适合我。我在启用状态下得到一个绿色按钮,然后在启用时没有阴影的灰色渐变为假。我是这样测试的(TestSkin 是你上面贴的皮肤):

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

    我认为问题与您使用皮肤的方式有关。你能把定义按钮本身的代码贴出来吗?

    【讨论】:

    • 啊!我想这会是这样愚蠢的事情。我正确设置了皮肤类,但我(在构建时在 Actionscript 中)设置了容器的启用设置,而不是按钮本身。我已经在上面的编辑中发布了相关代码。感谢您的调查!
    猜你喜欢
    • 1970-01-01
    • 2011-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-05
    • 2013-05-01
    • 1970-01-01
    相关资源
    最近更新 更多