开发者

Rolling Over a spark ItemRenderer switches the view state to default!

开发者 https://www.devze.com 2023-03-01 15:06 出处:网络
I\'m currently using flex sdk 4.5 (but it\'s the same with 4.1) and I have the following problem: I bind the current state of an ItemRenderer to an external object. This object is injected to the mxm

I'm currently using flex sdk 4.5 (but it's the same with 4.1) and I have the following problem:

I bind the current state of an ItemRenderer to an external object. This object is injected to the mxml view through Robotlegs injector.

the view has 4 states, everything works fine as long as I don't roll over the item itself. In this case, without any apparent explanation, the currentState switches to defaultstate even if the bound currentState variable hasn't changed is value. To solve this problem (and prove that the bound state value didn't change) I listen the added event of the button which is created when the state switches to default and force the currentState to switch again to the current value.

It works but it's obviously bad, can somebody tell me what's going on? Thank you!

please have a look at the following code:

<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_开发者_Go百科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>


Take a look at protected function getCurrentRendererState():String of spark.components.supportClasses.ItemRenderer (documentation) and override it properly.

0

精彩评论

暂无评论...
验证码 换一张
取 消