1

I have an Flex-Object with for example 3 properties.

myObj.prop1 myObj.prop2 myObj.prop3

I like to generate 3 Comboboxes to show the data. No problem if I do it hardcoded in sourcecode.

But how can I find the prop1 to prop3 at runtime?

If next time I have 5 properties with different name it should generate 5 combos.

Thanks for any help Jan

Jan Meyer
  • 33
  • 4
  • You can get the properties dynamically using a string, where propertyName is a string: instance1[propertyName]; Maybe a bit of code in your question, not fully sure if this is what you mean – Drenai Jul 06 '11 at 14:59

1 Answers1

2

Take a look at this question which shows you how to get all the properties in an object. Then just loop over them:

for each(var id:String in myObj) {
  // create ComboBox
  var combo : ComboBox = new ComboBox
  addChild(combo);
}

It is unclear from your post how the properties in the myObj relate tot he ComboBoxes you want to create. It is also unclear how you will distinguish your custom properties from the generic properties of an Object.

When defining dynamic properties like this, I prefer to use a Dictionary instead of an Object; but that is just my preference. Objects will work fine too.

Community
  • 1
  • 1
JeffryHouser
  • 39,401
  • 4
  • 38
  • 59
  • Thanks for all the help. It works fine now. I use ObjectUtil to get the properties and than myClass[propertyString] to get the values. Jan – Jan Meyer Jul 07 '11 at 09:41
  • @Jan Meyer IF this answer was indeed your solution; be sure to accept it as such. If not; please answer your own question and select that as the answer. – JeffryHouser Jul 07 '11 at 12:45