Flex: Changing states sometimes fail to change display
I have a flex3 web application that displays some data from the server on the same page by using the states class.
The MXML code part is this:
<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:Tab开发者_如何学JAVAularPanel>
</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 is using an AreaChart to display the data, while TabularPanel and ChatHistoryPanel use a DataGrid.
I switch between states by setting 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";
}
}
}
The initial state is 'Chart'.
Here's the problem:
Switching between states works fine except when I switch from 'ChatHistory' to 'List'. The display does not change but remains on the ChatHistoryPanel content.
I am totally clueless to what the problem may be. I wasn't able to find any solution. Any suggestion would be greatly appreciated, or even a workaround to what I'm trying to do.
I'm using: Flash Builder 4.5, Flex3, Windows 7, Chrome
Many thanks!
Ofer
In your state switching code, you have the following:
if (btnList.selected)
{
UsersDataController.getListOfParticipants();
currentState == "List"; //This checks equality instead of updating the property
}
And you should change this into:
if (btnList.selected)
{
UsersDataController.getListOfParticipants();
currentState = "List"; //This effectively updates your currentState property
}
It was thus a mere typo :P
Cheers
精彩评论