Using the trace() method
A useful way to find out what is going on within a Flex application is by using the trace() method built-in to Flex.
One of the key things that the trace() method allows you to add functionality to your application like client-side logging. The output created by the trace file is dumped to the flashlog.txt file. In order to see the trace output, you will first need to setup the your development environment to create the flashlog.txt file. More information on how to do this article on the Adobe site .
Detailed information on how to use the trace() method can be found in the Flex documentation .
A situation for utilizing the trace command would be when you want to write your own debug messages to a file during the development process. These messages can include specific text that aids you to understand the state of an application, but can also contain simple datatypes like String or int and complex datatypes like Objects, ArrayCollections, etc. To trace simple data types you don't need to do anything special. However, if you are dumping complex datatypes like Objects, you can use the toString() method of utility like mx.util.ObjectUtil to pretty-print the object as a string.
If you are creating your own ValueObjects (VOs), you can override the toString() method. Here is an example of how this can be accomplished:
var results : String = "obj_uuid={0}\r label={1}\r created={2}\r modified={3}\r owner={4}";
return StringUtil.substitute(results,[obj_uuid,label,created,modified,owner]);
}
Check any of the VOs generated by ZoomFlex for how this is implemented. Once you implement your own toString() method, the trace() method will display the the values of the VO in the format that you specify in the toString() method.
Also look at the Flex Logging API if you want to implement more sophisticated client-side logging.
Comments
There are no comments for this page as yet.
print page
