Flex:更改状态有时无法更改显示

时间:2011-07-06 07:23:40

标签: actionscript-3 flex flex3

我有一个flex3 Web应用程序,它使用状态类在同一页面上显示来自服务器的一些数据。

MXML代码部分是:

<mx:states>
    <mx:State name="Chart">
        <mx:AddChild position="lastChild">
            <ns2:ChartPanel right="10" top="182" left="10" bottom="10"></ns2:ChartPanel>
        </mx:AddChild>
    </mx:State>
    <mx:State name="List">
        <mx:AddChild position="lastChild">
            <ns2:TabularPanel right="10" top="182" left="10" bottom="10"></ns2:TabularPanel>
        </mx:AddChild>
    </mx:State>
    <mx:State name="ChatHistory">
        <mx:AddChild position="lastChild">
            <ns2:ChatHistoryPanel right="10" top="182" left="10" bottom="10"></ns2:ChatHistoryPanel>
        </mx:AddChild>
    </mx:State>
</mx:states>

ChartPanel 正在使用AreaChart显示数据,而 TabularPanel ChatHistoryPanel 使用DataGrid。

我通过设置currentState:

在状态之间切换
protected function onCriteriaChange(event:Event):void
{
    if (criteria.selectedLabel == "Chat History")
    {
    refreshChatHistory();
        currentState = "ChatHistory";
    }
    else
    {
    UsersModel.unique = criteria.selectedIndex;
    if (btnChart.selected)
    {
                    UsersDataController.getNumParticipants();
            currentState = "Chart";
        }
        if (btnList.selected)
        {
            UsersDataController.getListOfParticipants();
            currentState == "List";
        }
    }
}

初始状态为“图表”。

问题在于:

状态之间的切换工作正常,除非我从'ChatHistory'切换到'List'。显示不会改变,但会保留在ChatHistoryPanel内容上。

我完全不知道问题是什么。我无法找到任何解决方案。 任何建议都会受到高度赞赏,甚至可以解决我正在尝试做的事情。

我正在使用:Flash Builder 4.5,Flex3,Windows 7,Chrome

非常感谢!

奥弗

1 个答案:

答案 0 :(得分:2)

在状态切换代码中,您有以下内容:

    if (btnList.selected)
    {
        UsersDataController.getListOfParticipants();
        currentState == "List"; //This checks equality instead of updating the property
    }

你应该把它改成:

    if (btnList.selected)
    {
        UsersDataController.getListOfParticipants();
        currentState = "List"; //This effectively updates your currentState property
    }

因此这只是一个错字:P

干杯

相关问题