Tip: Dump any object to trace quickly

Heres a useful tip on using the mx utils package.

Occasionally we need to trace values of objects, whether these are flash display objects or your own classes and VOs.   Simply outputting an object to trace will generate an output like [Object Object] without any useful info about the contents of the object.

Enter mx.Utils and its helper classes. ObjectUtil is a nifty little class that contains some helper functions (check it out on Adobe live docs) and the static toString() implementation offers to ‘pretty print’ any object.

Simply type:

        // assume myObject is defined elsewhere

and replace your object as the function argument.

Short example:

        var point:Point = new Point(100, 100);
    //Will output:
         length = 141.4213562373095
         x = 100
         y = 100

Try it out!