views:

363

answers:

1

Below is part of my code interacting with data grid...!

This lists the children of the particular node if i click on it after refreshing the datagrid..

But if i click on an empty space of the datagrid i get an error saying

"ReferenceError: Error #1069: Property data not found on mx.controls.listClasses.ListBaseContentHolder and there is no default value."

How to avoid that ?

if(event.target.data.children != null) { resultSet.removeAll(); var tempChildObj:ArrayCollection; tempChildObj=event.target.data.children as ArrayCollection; var childLength:int; childLength=tempChildObj.length;

  for(var i:int =0;i<childLength;i++)
  {

   resultSet.addItem(tempChildObj.getItemAt(i));

  }

  resultSet.addItem(tempChildObj);
 }


}
+1  A: 

What the error is telling you is that the event's target property doesn't have a property called data in your error case. This makes sense since you're clicking on a blank row - a blank row won't contain any data.

What you'll want to do first is check if the event's target contains a data property before you start accessing the child property of data. Either one of the following tests should work:

if( event.target.hasOwnProperty( "data" ) ) {
    // rest of your code here
}

or

if( event.target.data ) {
    // rest of your code here
}
Dan