Check out mx.utils.ObjectUtil, especially getClassInfo

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Paolo Bernardini
Sent: Monday, April 16, 2007 5:22 AM
To: [email protected]
Subject: Re: [flexcoders] for in loop dosen't work on custom class



sorry for the * it was a copy and past problem.
Thanks Shaun, for your explanation.
I need the for in loop not to add new properties to my object, but to
iterate through its properties and add them to a new object.

 
On 16 Apr 2007 04:39:03 -0700, shaun <[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> > wrote: 

        Paolo Bernardini wrote:
        > I found that if you try to do a for in loop for a custom class
it won't
        > work.
        > 
        > *for* (*var* i:String *in* ItemVO*){*
        > * trace*(ItemVO[i]); // it won't trace anything. 
        > }
        > 
        
        [snip]
        
        > *public* *class* ItemVO *implements* IValueObject
        > 
        
        [snip]
        
        The "for in" loop only iterates over dynamic properties. Not
fixed.
        You can either make your object dynamic. 
        
        public dynamic class ItemVO implements IValueObject
        
        Or you have to use flash.utils describeType to get an XML
representaion 
        (minus static properties, I think).
        
        Dynamic objects can make life easier in a lot of ways,
especially with 
        item renderers and editors, but beware the downside. You can set
and 
        access properties that are not part of the class, same as you
can with a 
        Plain Old Actionscript Object instance (POAO ;). So a simple
typo could 
        create real hassles, rather than being caught be the compiler.
        
        Ie) you can do the following:
        
        var item:ItemVO = new ItemVO();
        
        item.property_that_doesnt_exist = "a value";
        
        or
        
        var s:String = item.property_that_doesnt_exist;
        
        cheers,
        - shaun
        

        


 

Reply via email to