Accessibility

Table of Contents

Debugging Client-Side Code in Flex Applications

Flex’s XMLObjectOutput

While the trace() function is a great way to display simple data types and other information, it does not help when you debug more complex data structures like models and trees. For discovering information about these data structures, Flex provides an undocumented utility called XMLObjectOutput that logs simple string data to the flashlog.txt by tracing the values and attributes of XML objects, arrays and other ActionScript objects.

XMLObjectOutput is an ActionScript class that converts XML objects to simple object types. The XMLObjectOutput.as class is included in the Flex distribution in the {flex.rootdir}/extras/XMLObjectOutput directory. To use the XMLObjectOutput utility, copy the XMLObjectOutput.as file to the Flex user_classes directory. By default, the user_classes directory is located at {flex.rootdir}/jrun4/servers/default/flex/WEB-INF/flex/user_classes.

To leverage the utility in ActionScript, simply instantiate an instance of the XMLObjectOutput object as follows.

var myDebugger:XMLObjectOutput = new XMLObjectOutput() ;

Next, use the traceObject() method to output a representation of the data structure to the flashlog.txt as follows.

myDebugger.traceObject( myEmployeeModel );

Consider the following XML model view in MXML as well as the XMLObjectOutput representation of the data from the flashlog.txt.

The MXML representation of XML data:

The MXML representation of XML data:
 <mx:Model id="myEmployee">
   <employee employeeId="5">
            <firstName>John</firstName>
            <lastName>Smith</lastName>
            <phone>617-219-3345</phone>
   </employee>
 </mx:Model>
XMLObjectOutput representation of the same data
Object:  [object Object]
 |-- employee [object]
       |-- employeeId: 5
       |-- firstName: John
       |-- lastName: Smith
       |-- phone: 617-219-3345
	   

The XMLObjectOutput class provides a detailed view into even very complex XML schema.