2 Replies Latest reply on Jul 11, 2007 12:12 PM by MaxMuld

    Error when change state in datagrid change event

    MaxMuld
      Hi. The very simple code below produce an error. It happens when you try to change state from base state to state 1 in the procedure which is started from the datagrid change event (when you click on a row in the datagrid).

      I think the problem is that the datagrid isn't defined in state 1 which means that it is removed at state change. But you can't apperantly remove the datagrid while you are in a middle of an change event and that's probably why you get the error. It all works fine if I don't remove the datagrid from state 1.

      can anyone help with a solution because in my opinion it is very convenient and a common method to switch to another form/display when a user clicks on a row in a datagrid. Isn't it possible in flex to change state somehow when the user clicks on a datagrid row?


      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" >
      <mx:Script>
      <![CDATA[
      import mx.events.ListEvent;

      public function EditScreen(event:ListEvent):void {
      currentState='state1';
      }
      ]]>
      </mx:Script>

      <mx:states>
      <mx:State name="state1">
      <mx:AddChild position="lastChild">
      <mx:Button label="Back" click="currentState=''" />
      </mx:AddChild>
      <mx:RemoveChild target="{datagrid1}"/>

      </mx:State>
      </mx:states>

      <mx:Array id="TestArray">
      <mx:Object col1="line 1" col2="line 1" />
      <mx:Object col1="line 2" col2="line 2" />
      </mx:Array>

      <mx:DataGrid dataProvider="{TestArray}" change="EditScreen(event)" id="datagrid1">
      <mx:columns>
      <mx:DataGridColumn headerText="Column 1" dataField="col1"/>
      <mx:DataGridColumn headerText="Column 2" dataField="col2"/>
      </mx:columns>
      </mx:DataGrid>

      </mx:Application>