views:

3546

answers:

5

I have a dataprovider and a filterfunction for my array that's assigned to my dataprovider.

How can I get a list of the properties that are in each row of the dataprovider (item.data) as it gets passed to the filterfunction?

For instance, if my object contained:

Object name email address

Then I would want, in my filterfunction to be able to look at name, email and address. Unfortunately, I don't know what these properties will be before hand.

Any ideas?

G-Man

+2  A: 

If it's a dynamic object I believe you can just do something like this:

var obj:Object; // I'm assuming this is your object

for(var id:String in obj) {
  var value:Object = obj[id];

  trace(id + " = " + value);
}

That's how it's done in AS2, and I believe that still works for dynamic objects in AS3. I think the properties that it will show is more limited on non-dynamic objects.

Herms
Perfect! Works great. Been trying to figure that out for days. Thanks very much!G-Man
GeoffreyF67
A: 

you can use a for .. in loop to get the properties names, or a for each .. in loop to get the property values ...


for( var o : * in object){
    trace( o + " = " + object[o] );
}
/************* OR ******************/
for each( var o : * in object ){
    trace( "object has property: " + o );
}
ForYourOwnGood
A: 

for-in works for dynamic objects only. For typed objects you need to use some kind of reflection to get property names (e.g. http://www.as3commons.org/as3-commons-reflect/index.html)

/Andrei.

A: 

You are probably looking for

ObjectUtil.getClassInfo(object)

,see:

http://livedocs.adobe.com/flex/3/langref/mx/utils/ObjectUtil.html#getClassInfo%28%29

Be aware that there is a bug in it which causes it to treat XML as a non-dynamic data type. More on the bug in: bugs.adobe.com/jira/browse/SDK-17712

Robert Bak
+1  A: 

describeType(object) will also give you a list of properties on an object.

Joel Hooks