2011-11-14 44 views
1

我試圖爲Spark按鈕創建一個Flex 4皮膚,這是典型的做法。我根據自己的喜好調整了顏色和其他樣式,包括使用點選擇器在不同狀態下指定替代顏色等。但是,當按鈕被禁用時,這些都將被忽略。無論我做什麼,在禁用狀態下,我的按鈕始終顏色不正確,並且字母爲0.5(即使我明確指出alpha.disabled =「1」)。所有其他皮膚狀態按預期工作。這裏發生了什麼?Flex 4按鈕外觀被禁用Alpha設置被忽略?

這是我的自定義皮膚。如果它工作正常,它看起來沒有陰影或高光,並且將是漸變的灰色。相反,它表現爲上升狀態(閃亮的綠色)的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;解決了這個問題。

回答

2

你的皮膚適合我。我在啓用狀態下得到一個綠色按鈕,然後啓用時沒有投影的灰色漸變爲false。我測試它像這樣(其中TestSkin是你的皮膚上面貼):

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

我認爲問題與您如何使用皮膚做。你可以發佈代碼按鈕本身的定義?

+0

Gah!我認爲這將是一件愚蠢的事情。我正確設置了皮膚類,但我(在構建時在Actionscript中)設置容器的啓用設置,而不是按鈕本身。我已在上面的修改中發佈了相關代碼。感謝您的關注! – Dwight