flex 3 iterate through object values

cdugga picture cdugga · Mar 23, 2009 · Viewed 25k times · Source

i have an object which represents a database table. I want to iterate through this object and print printing each value. What can i use to do this?

i want to do this inside my mxml not actionscript

for each object attribute i want to create an imput field

Answer

dirkgently picture dirkgently · Mar 23, 2009

Look up the documentation on Flex 3 looping. If you do, you'll find this:

for..in

The for..in loop iterates through the properties of an object, or the elements of an array. For example, you can use a for..in loop to iterate through the properties of a generic object (object properties are not kept in any particular order, so properties may appear in a seemingly random order):

var myObj:Object = {x:20, y:30};
for (var i:String in myObj)
{
    trace(i + ": " + myObj[i]);
}
// output:
// x: 20
// y: 30

Instead of trying to create an input field for each object, I'd suggest you take a look at DataGrid and custom ItemEditors.