2011-04-26 81 views
0

我在我的应用程序中使用了状态。事情是我已经使我的列表中的第一项被选中。所以我给了这个样子,在flex中切换状态4

if(itemIndex == 0) 
    this.currentState="selected"; 

这个工程罚款。问题是,当其他项目被选中的第一个项目不会改变其状态,但仍处于选中状态,直到它的点击。 我的代码看起来像这样,

<s:BorderContainer id="outerCont" width="275" height="100" borderVisible="false" 
         backgroundColor.normal="#3D3C3C" backgroundAlpha.selected="0.1" 
         backgroundColor.selected="{data.color}"> 

我的状态是这样的,提前

<s:states> 
    <s:State name="normal" /> 
    <s:State name="hovered" /> 
    <s:State id="selState" name="selected" /> 
</s:states> 

谢谢!

回答

1

在您更改状态的代码中,您永远不会回到默认状态。所以,当itemIndex是0时;你设置为选中状态;但没有显示代码从选定状态移开。尝试是这样的:

<s:List change="onChange()" /> 

<fx:Script><[[ 
    public function onChange():void{ 
    if(itemIndex == 0) 
    this.currentState="selected"; 
    else 
    this.currentState="someOtherState"; 
    } 
]]></fx:Script> 

是否帮助:

if(itemIndex == 0) 
    this.currentState="selected"; 
else 
    this.currentState="someOtherState"; 

当在Flex列表中选择一些你可以使用更改事件要更改状态?如果不;你将不得不详细说明一点。

+0

嘿谢谢你的回复,我的期望是默认情况下应用程序加载第一个项目时应该选择。因此,在creationComp我给了代码if(itemIndex == 0) this.currentState =“selected”; 。然后,当任何其他项目被点击时,默认选择的第一个项目不会被取消选择,除非和直到它再次点击。因此,我有两个项目被选中。希望清除它现在.. – Naveen 2011-04-27 04:34:21

+0

@Naveen您的评论其实是更混乱。对于许多基于Flex列表的组件;默认状态是“没有选择”。由于您从未告诉我们您正在使用什么组件,以及如何选择项目;接下来告诉你什么,我不知所措。我建议你添加更多的代码,可能是一个可运行的样本来展示你的问题。 – JeffryHouser 2011-04-27 13:43:09

+0

嘿,对不起,我会尝试清楚解释你这次。我正在尝试类似于以下链接中发布的内容。 http://blog.flexexamples.com/2010/01/27/creating-a-fancy-spark-list-control-item-renderer-in-flex-4/.I遵循相同的代码,唯一的补充我有由是我创作完成方法我已经作出选择我的第一个项目,像这样的“保护功能itemrenderer1_initializeHandler():无效 \t \t \t { \t \t \t \t如果(this.itemIndex == 0) \t \t \t \t { \t \t \t \t \t //this.selected=true; \t \t \t \t this.currentState =“selected”; \t \t \t \t \t validateNow(); \t \t \t \t} \t \t \t}” – Naveen 2011-04-28 04:49:56