2
我目前使用flex sdk 4.5(但它與4.1相同),我有以下問題:Rolling Over a spark ItemRenderer將視圖狀態切換爲默認值!
我將ItemRenderer的當前狀態綁定到外部對象。該對象通過Robotlegs注入器注入到mxml視圖中。
該視圖有4個狀態,只要我不滾動項目本身,一切正常。在這種情況下,即使沒有任何明顯的解釋,currentState切換到默認狀態,即使邊界currentState變量沒有改變是值。爲了解決這個問題(並且證明綁定狀態值沒有改變),我監聽當狀態切換到默認狀態時創建的按鈕的添加事件,並強制currentState再次切換到當前值。
它的作品,但它顯然是不好的,有人可以告訴我發生了什麼事?謝謝!
請看看下面的代碼:
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:modelviews="it.addme.MVVM.modelviews.*"
width="150" height="100" autoDrawBackground="true"
currentState="{modelView.currentState}"
>
<fx:Script>
<![CDATA[
import it.addme.MVVM.modelviews.AddMeButtonPresenter;
[Inject]
[Bindable]
public var modelView:AddMeButtonPresenter;
override public function set data(value:Object):void
{
panel.title = value.appName;
}
protected function button1_addedHandler(event:Event):void
{//I need this to solve the roll-over problem
currentState = modelView.currentState;
}
]]>
</fx:Script>
<s:states>
<s:State name="default" />
<s:State name="USER_UNKNOWN" />
<s:State name="USER_EXISTS" />
<s:State name="USER_DOESNT_EXIST" />
</s:states>
<s:Panel left="0" top="0" width="150" height="100" id="panel">
<s:Button includeIn="USER_UNKNOWN" label="Checking..." enabled="true" horizontalCenter="0"
verticalCenter="0"/>
<s:Button includeIn="USER_EXISTS" label="Unsubscribe" click="modelView.unsubscribe()"
enabled="true" horizontalCenter="0" verticalCenter="0"/>
<s:Button includeIn="USER_DOESNT_EXIST" label="Subscribe" click="modelView.subscribe()"
enabled="true" horizontalCenter="0" verticalCenter="0"/>
<s:Button includeIn="default" label="..." added="button1_addedHandler(event)"
horizontalCenter="0" includeInLayout="false" verticalCenter="0"/>
</s:Panel>
</s:ItemRenderer>