1 Reply Latest reply on Jan 17, 2008 9:29 AM by m_hartnett

    Looping of Object Instance

      How can I loop though public properties of an instance of an object? I don;t want to write out each property of the class to check its value. The object has a basic class which just holds all the values which will be passed to a script for processing
        • 1. Re: Looping of Object Instance
          m_hartnett Level 3
          If you have a simple object ( not an MXML class) you can do it a couple of ways:

          //just setting up the object
          var o : Object = new Object();
          o.item1 = "pppp";
          o.itemX = "54545";

          //This gets the properties of the object to be used in the loop below
          var objPropsA : Array = ObjectUtil.getClassInfo(o).properties;

          for(var x:int=0;x<objPropsA.length;x++) {
          var obj : Object = objPropsA[x];
          var item :String = o[obj] ;

          //This is a shorthand loop for doing the same thing as above.
          for each( var obj:Object in ObjectUtil.getClassInfo(o).properties ) {
          var item :String = o[obj] ;