2012-01-12 105 views
0

因此,我創建一個自定義切換按鈕,包括財產CurrentValue的:整數重繪/刷新自定義皮膚

這樣我可以執行下列操作...

<fx:Script> 
    protected var currentValue:int = 0; 
    protected function changeValue(x:int):void{ 
     currentValue = x; 
    } 
</fx:Script> 

<MyToggleButton currentValue="{updatedValue}" styleName="MyToggleStyle" click="changeValue(1)" id="first"/> 
<MyToggleButton currentValue="{updatedValue}" styleName="MyToggleStyle" click="changeValue(2)" id="second"/> 

這個腳本的想法是基於currentValue中的改變而改變的切換按鈕的外觀。每次我如何刷新切換按鈕,以便根據「currentValue」中的更改更新樣式?

P.S. MyToggleStyle將引用以mxml編寫的Skin類,該類將使用getStyle(「currentValue」)獲取當前值的更改

回答

0

如果currentValue屬性只會影響皮膚圖形,並且您有幾個預定義的「看起來「,那麼你應該創建一個具有狀態的皮膚。 (見spark.skins.spark.CheckBoxSkin一個很好的例子。)

在MyToggleButton

public function set currentValue(value:int):void { 
    _currentValue = value; 
    invalidateSkinState(); 
} 

protected override function getCurrentSkinState():String { 
    return _currentValue == 9 ? "someStateName" : "otherState"; 
} 

這會取消你的皮膚狀態,每當currentValue變化和Flex會自動調用getCurrentSkinState(),以確定你的皮膚的新狀態。然後,您可以在皮膚內使用includeIn,條件屬性等來確定其外觀。

如果要在皮膚中顯示currentValue作爲文字,您應該查看皮膚部位。這些基本上是您的組件定義的插槽,然後皮膚會使用諸如標籤之類的組件進行「填充」。例如,標準火花按鈕上的標籤是外觀部件labelDisplay。該組件可以直接在其上設置文本,但實際創建它取決於皮膚。

P.S.您的示例代碼中的currentValue還需要[Bindable]