haXe Forum > iterate class

  • A small question, is it possible to iterate all class variables ?
    for exemple, if a I have a class like this :

    class ItClass 
    {
        public var onething:String;
        public var twothing:String;
        public var threething:Int;
        
        public function new() 
        {
            onething = "un";
            twothing = "deux";
            threething = 3;
        }
    }

    is it possible to retrieve the three properties with an instance of ItClass ? (the best would be to have the property, the type and the value of, if it is set) !

  • Check out Type, there is a "getInstanceFields" function.

  • Thanks Andy, but there's still a problem for me.
    With Type.getInstanceFields (myclass), I'm able to find all fields, but how can I access to those fields in an instance of myclass.
    In Flash, I would do myInstance[field], but it doesn't work here...

  • it's ok, I've just found it ! It is with the Reflect class :)

< Prev | Page 1 / 1 | Next >