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

    Error when change state in datagrid change event

      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" >
      import mx.events.ListEvent;

      public function EditScreen(event:ListEvent):void {

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


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

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