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.

[code]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)); } } }[/code] This will output the object in a more human readable format like so: [code](Object)#0 arr = (Array)#1 [0] (Object)#2 name = "Homer" [1] (Object)#3 name = "Bart" foo = "bar" [/code] You can view the docs for the api here. You can download the Flex 2 beta from labs.

Comments

  1. Ben
    April 12, 2006 12:00 PM
    I saw your post on Flexcoders about this earlier and I cannot believe I didn't look for something like sooner. Its a life saver. Bye bye to my nested for...in's.
  2. sebi
    April 13, 2006 3:12 AM
    is there any source code available for this? it would be so useful in flash development too.
  3. April 13, 2006 8:27 PM
    I believe a similar method exists in the v2 component architecture, although the exact method escapes me... For something more lightweight you do something like Keith Peters did in flash 7+: http://www.bit-101.com/blog/?p=535

Post a comment




Remember Me?

(you may use HTML and Quickcode tags for style)