我目前正在使用flex sdk 4.5(但与4.1相同)我有以下问题:
我将ItemRenderer的当前状态绑定到外部对象。该对象通过Robotlegs注入器注入mxml视图。
视图有4个状态,只要我不翻转项目本身,一切正常。在这种情况下,没有任何明显的解释,即使绑定的currentState变量未更改,currentState也会切换到defaultstate。要解决这个问题(并证明绑定状态值没有改变),我会听到当状态切换到默认状态时创建的按钮的添加事件,并强制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>
答案 0 :(得分:3)
查看protected function getCurrentRendererState():String
spark.components.supportClasses.ItemRenderer
(documentation)的{{1}}并正确覆盖它。