我有一個3狀態的皮膚。未來我可能會有更多的州。但它是一個正常狀態的工具欄,然後是一次只能顯示一個展開視圖的展開視圖。取消狀態轉換並直接轉到另一個視圖
當我有兩種狀態時,我可以使用下面的轉換代碼輕鬆地在兩者之間切換。但是現在我有三個州,次要州沒有關閉。如果我處於第二狀態,我想先關閉它。
這裏是從皮膚類我的代碼:
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
protected function imageViewButton_clickHandler(event:MouseEvent):void
{
if (currentState==NORMAL_VIEW) {
currentState = IMAGE_VIEW;
}
else {
currentState = NORMAL_VIEW;
}
}
protected function linkViewButton_clickHandler(event:MouseEvent):void
{
if (currentState==NORMAL_VIEW) {
currentState = LINK_VIEW;
}
else {
currentState = NORMAL_VIEW;
}
}
public static var NORMAL_VIEW:String = "normal";
public static var LINK_VIEW:String = "linkView";
public static var IMAGE_VIEW:String = "imageView";
]]>
</fx:Script>
<s:transitions>
<s:Transition fromState="normal" toState="*">
<s:Sequence duration="250">
<s:Resize target="{this}"/>
<s:AddAction target="{linkViewButton}"/>
<s:Fade target="{linkViewButton}"/>
</s:Sequence>
</s:Transition>
<s:Transition fromState="linkView" toState="*">
<s:Sequence duration="250">
<s:Fade target="{linkViewButton}"/>
<s:Resize target="{this}"/>
</s:Sequence>
</s:Transition>
<s:Transition fromState="imageView" toState="*">
<s:Sequence duration="250">
<s:Fade target="{imageViewButton}"/>
<s:Resize target="{this}"/>
</s:Sequence>
</s:Transition>
</s:transitions>
<s:states>
<s:State name="normal"/>
<s:State name="linkView"/>
<s:State name="imageView"/>
</s:states>
<s:VGroup width="100%">
<s:HGroup width="100%" >
<s:Button label="Button 1" />
<s:Line height="100%">
<s:stroke>
<s:SolidColorStroke color="#B3C2B8"/>
</s:stroke>
</s:Line>
<s:ToggleButton id="gotoLinkView" label="Link Details" click="linkViewButton_clickHandler(event)"/>
<s:Line height="100%">
<s:stroke>
<s:SolidColorStroke color="#B3C2B8"/>
</s:stroke>
</s:Line>
<s:ToggleButton id="gotoImageView" label="Image Details" click="imageViewButton_clickHandler(event)"/>
<s:Line height="100%">
<s:stroke>
<s:SolidColorStroke color="#B3C2B8"/>
</s:stroke>
</s:Line>
</s:HGroup>
<s:Button id="linkViewButton" label="Link View"
includeIn="linkView"
itemCreationPolicy="immediate" width="100%"/>
<s:Button id="imageViewButton" label="Image View"
includeIn="imageView"
itemCreationPolicy="immediate"
width="100%"/>
</s:VGroup>
</s:WindowedApplication>