Home > Flex > Flex Tip of the Day: Call enterDebugger() to break into the debugger programmatically

Flex Tip of the Day: Call enterDebugger() to break into the debugger programmatically

May 29th, 2007

Here’s a quickie: Flex Builder doesn’t provide conditional breakpoints, but you can code them yourself by calling flash.debugger.enterDebugger(). For example, if you want to set a breakpoint to go off the nth time you enter a method, you can just write code similar to:

if (breakCount++ == 3)
    enterDebugger();

We also use enterDebugger() in our implementation of Assert so that by default, if an Assert fires, the application breaks into the debugger.

Technorati Tags: , , ,

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
Author: David Coletta Categories: Flex Tags:
  1. May 30th, 2007 at 17:09 | #1

    Thanks David. Another really interesting tip.

  2. June 2nd, 2007 at 12:04 | #2

    You could always do something like:
    if(condition)
    trace(something);

    and put a breakpoint on the “trace” line….

    It accomplishes the same thing with an added “trace” statement. :) Yours is more explicit, but with mine, if I decide in the middle of a debug session that I don’t want to hit that breakpoint the next time the condition is true, I can just remove it an hit “play”.

    Any reason you could see that we wouldn’t do this?

  3. david
    June 2nd, 2007 at 12:26 | #3

    Yeah, for ad-hoc debugging, what you describe sounds equivalent. The enterDebugger() function is most useful in cases where you bottleneck a lot of code through a single path and always want to drop into the debugger in that path, such as your Assert function.

Comments are closed.