mike chambers | about

Using ObjectUtil.toString() to trace properties of an Object

If you need to get a quick view into an Object or class instance, you can use the mx.utils.ObjectUtil.toString() API included in the Flex 2 Framework.

package
{
	import flash.display.Sprite;

	public class ViewType extends Sprite
	{
		import mx.utils.ObjectUtil;
		import flash.util.trace;

		public function ViewType()
		{

			var o:Object = new Object();
				o.foo = "bar";
				o.arr = [{name:"Homer"}, {name:"Bart"}];

			trace(ObjectUtil.toString(o));
		}
	}
}

This will output the object in a more human readable format like so:

(Object)#0
  arr = (Array)#1
    [0] (Object)#2
      name = "Homer"
    [1] (Object)#3
      name = "Bart"
  foo = "bar"

You can view the docs for the api here.

You can download the Flex 2 beta from labs.

Tags:
twitter github flickr behance