Debugging Flex 2.0.1 Modules

Filed under: Articles — Robert Taylor at 7:59 pm on Thursday, March 15, 2007

Flex 2.0.1 was released with the ability to create modules...

"Modules are SWF files that can be loaded and unloaded by an application. They cannot be run independently of an application, but any number of applications can share the modules. Modules let you split your application into several pieces." - Adobe

This isn't a new concept. If you develop in Flash you do this all the time. So its nice that Flex now supports this as well. The nice thing about modules are they do not compile with classes that exist in the their SWF counterparts. So if SWFA is loading SWFB and SWFB has a class that is also in SWFA, then SWFB will not compile with that class (or component) -- resulting in smaller file size. Nice!

Now the bad news, there is a known issue with modules as mentioned here. Breakpoints are not supported in modules. If you work in Flex, you know how important the debugger is in finding problems in code. You can't live without it. Well, here is a nice solution for now for debugging your modules I came up with...

Create a class called Debug. Mine is located in a folder called utils.

Actionscript:
  1. package utils
  2. {
  3. public class Debug
  4. {
  5. public static function breakpoint(...rest:Array):void
  6. {
  7. // ...put a breakpoint on this line...
  8. }
  9. }
  10. }

Now in Flex put a break point on the line that says "// ...put a breakpoint on this line...".

In your Module you can now create psuedo breakpoints. Wherever you would like to monitor data, just call the Debug function:

Example:

Actionscript:
  1. public function test():void
  2. {
  3. Debug.breakpoint(this);
  4. }

You can pass any number of parameters in that you would like to evaluate. Hope this helps other that are using Modules in Flex 2.

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

You must be logged in to post a comment.