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: ActionScript, Flex, Flex Builder, Flex Tip of the Day




Thanks David. Another really interesting tip.
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?
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.