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



I'm working on Noteflight, an online music writing application that lets you create, view, print and hear music notation with professional quality, right in your web browser. Work on a score from any computer on the Internet, share it with other users, and embed it in your own pages. Noteflight is free for individual use. Email me at dcoletta at noteflight dot com.

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.