views:

78

answers:

2

I have a dynamic class that I have created

public dynamic class SiteZoneFileUploadVO
{       
    public var destination:String = "sitezone";
    public var siteZoneId:uint;
    public var fileType:String;
    public var fileContents:String;

    public function SiteZoneFileUploadVO()
    {
    }

}

when I try to iterate over this object's property names it only iterates the dynamically added properties.

        parameters.dynVar= "value";

        for(var name:String in parameters) 
        {
            trace(name);
        }

Even though the object has all the properties equal to a value (ive checked this in the debugger) the only property name that will be traced is dynVar.

How can I iterate over all the property names and not just the dynamically added ones?

A: 

Just use trace(ObjectUtil.toString(parameters)); That should give you your entire object.

invertedSpear
While `ObjectUtil.toString()` can be used to print out all properties of an object, it does so in a single String. That makes it imho unpractical for accessing single properties and basically completely rules out any sort of looping.
Baelnorn
@Baelnorn - Agreed, it's an ugly, ugly dump, but useful when that's all you need. I skimmed the question too much, didn't realize the OP was looking for more than a dump
invertedSpear
+2  A: 

You can use describeType() to get an XML with all methods and variables of your class and then filter out the properties you want to iterate over (e.g. all variables) and store them in an XMLList.

As the next step you would then iterate over the XMLList and use square bracket notation on your object to access the filtered properties by their names. However, you can only access public properties this way because describeType() won't look at private properties.

Baelnorn
Baelnom speaks correctly - you can't iterate over dynamic and static properties with for (var name in parameters) - only can iterate over dynamic properties.
sksizer