Determining an Object Based on Property

I had an error thrown in Flex recently which was Property type not found on ’ A Class Object ’ and there is no default value.. In a nut shell I had an ArrayCollection of Value Objects and amongst them was one particular Object I wanted removing from the ArrayCollection ready for storage. I have defined this Object above as A Class Object, and this particular class was different to the rest as I had not defined a ‘type’ property.

The way to tackle this is highlight below. Essentially I loop through each Object in the ArrayCollection and use the Object.hasOwnProperty() method that returns a Boolean dependent on the presence of the property parameter on the Object.

1
2
3
4
5
6
7
8
for each ( var initObj:Object in myArrayCollection )
{
  if( !initObj.hasOwnProperty( 'type' ) )
  {
      Logger.info("The Object: " + initObj + " has no type parameter");
      myArrayCollection.removeItemAt( myArrayCollection.getItemIndex( initObj ) );
  } 
}

Comments