One recommendation I would make to the Engineers at Adobe is that the global trace(); method in Flex 2 become a bit more robust. Just as in previous versions of Flex and Flash the trace method only handles simple types; String, Boolean, Number, int, unit etc.
Flex 1.5 had a really good object debugger available but I have yet to find something similar for Flex 2. So I decided to build my own debugger to handle recursively tracing objects of complex type; Array, Collections, Object etc.
The Flex2LocalDebugger is a simple Object debugger API which uses LocalConnection for tracing objects of both simple and complex types to a debugger console. Flex2LocalDebugger does not provide a logging API, however users could easily extend FlexLocalDebugger to add logging capabilities.
The LocalDebugger console runs in a browser so you can easily switch between your application and the debugger from within the same browser, without the need to to run the debug player. This is useful for when you simply want to trace an object of complex type without running the Debug version of Flash Player.
The main entry point into the FlexLocalDebugger API is the LocalDebugger class. The LocalDebugger class provides methods which allow objects to be sent to the debugger console as well as displayed in an Alert window:
- trace();
Checks to see if the object specified is of simple or complex type. If the object is of simple type LocalDebugger will send the object to the debugger console. If the object is of complex type, LocalDebugger will recursively trace the object and all elements of the object to the debugger console.
- send();
Allows users to bypass recursive tracing and send an object directly to the console.
- show();
Traces an object to an mx.controls.Alert window. Similar to trace, mx.controls.Alert will only trace a String in an Alert window. For ease of use, FlexLocalDebugger handles casting an object to String and displaying the object in an Alert window within the application.
- allowConnection();
Terminates / allows all connections to LocalDebugger
The debugger will recursively trace an object of complex type. Each call to LocalDebugger.trace(); prints a [trace-object-root] when tracing a new object. This is the root of the top level object which has been specified as the parameter in a call LocalDebugger.trace();.
To use the Flex2LocalDebugger API in your application, simply right-click on your project and select: properties > Flex Build Path > Library Path > Add SWC. Browse to the location of FlexLocalDebuggerAPI.swc and click ok.
You can download the swc as well as view the documentation for the Flex Local Debugger API.
Flex2LocalDebugger is protected under the MIT Licence.
Flex Builder comes with an excellent debugger as well.
Nonetheless, it’s great that free tools becomes available 🙂
Flex Builder’s Debugger is perfect for debugging Flex Applications, FlexLocalDebugger is intended for recursively tracing objects of complex type to a local connection at runtime in order to facilitate remote debugging without the debugger.
Mike Morearty has an excellent blog which is dedicated to Flex Builder’s Debugger.
http://www.morearty.com/blog/feed/
FlexLocalDebugger is a simple object debugger which is not intended to rival Flex Builder’s debugger, it’s not even intended to be similar in anyway, it’s purpose is for tracing objects of complex type to a console window which can run outside of the Debug Player.