Adobe Flex 3 Help

Setting breakpoints

Setting breakpoints is a critical aspect of debugging any application. You can set breakpoints on any ActionScript code in your Flex application. You can set breakpoints on statements in any external ActionScript file, on ActionScript statements in an <mx:Script> tag, or on MXML tags that have event handler properties. In the following MXML code, click is an event handler property:

<mx:Button click="ws.getWeather.send();"/>

Breakpoints are maintained from session to session. However, when you change the target file or quit fdb, breakpoints are lost.

The following table summarizes the commands for manipulating breakpoints with the ActionScript debugger:

Command

Description

break [args]

Sets a breakpoint at the specified line or function. The argument can be a line number or function name. With no arguments, the break command sets a breakpoint at the currently stopped line (not the currently listed line).

If you specify a line number, fdb breaks at the start of code for that line. If you specify a function name, fdb breaks at the start of code for that function.

clear [args]

Clears a breakpoint at the specified line or function. The argument can be a line number or function name.

If you specify a line number, fdb clears a breakpoint in that line. If you specify a function name, fdb clears a breakpoint at the beginning of that function.

With no argument, fdb clears a breakpoint in the line that the selected frame is executing in.

Compare the delete command, which clears breakpoints by number.

commands [breakpoint]

Sets commands to execute when the specified breakpoint is encountered. If you do not specify a breakpoint, the commands are applied to the last breakpoint.

condition bnum [expression]

Specifies a condition that must be met to stop at the given breakpoint. The fdb debugger evaluates expression when the bnum breakpoint is reached. If the value is true or nonzero, fdb stops at the breakpoint. Otherwise, fdb ignores the breakpoint and continues execution.

To remove the condition from the breakpoint, do not specify an expression.

You can use conditional breakpoints to stop on all events of a particular type. For example, to stop on every initialize event, use the following commands:

(fdb) break UIEvent:dispatch Breakpoint 18 at 0x16cb3: file UIEventDispatcher.as, line 190 (fdb) condition 18 (eventObj.type == 'initialize')
delete [args]

Deletes breakpoints. Specify one or more comma- or space-separated breakpoint numbers to delete those breakpoints. To delete all breakpoints, do not provide an argument.

disable breakpoints [bp_num]

Disables breakpoints. Specify one or more space-separated numbers as options to disable only those breakpoints.

enable breakpoints [bp_num]

Enables breakpoints that were previously disabled. Specify one or more space-separated numbers as options to enable only those breakpoints.

The following example sets a breakpoint on the myFunc() method, which is triggered when the user clicks a button:

(fdb) break myFunc 
Breakpoint 1 at 0x401ef: file file1.mxml, line 5
(fdb) continue 
Breakpoint 1, myFunc() at file1.mxml:5
 5ta1.text = "Clicked";
(fdb)

To see all breakpoints and their numbers, use the info breakpoints command. This will also tell you if a breakpoint is unresolved.

You can use the commands command to periodically print out values of objects and variables whenever fdb encounters a particular breakpoint. The following example prints out the value of ta1.text (referred to as $1), executes the where command, and then continues when it encounters the button's click handler breakpoint:

(fdb) commands 1 
Type commands for when breakpoint 1 is hit, one per line.
End with a line saying just 'end'.
>print ta1.text 
>where 
>continue 
>end 
(fdb) cont 
Breakpoint 1, myFunc() at file1.mxml:5
 5ta1.text = "Clicked";
$1 = ""
#0 [MovieClip 1].myFunc(event=undefined) at file1.mxml:5
#1 [MovieClip 1].handler(event=[Object 18127]) at file1.mxml:15

Breakpoints are not specific to a single SWF file. If you set a breakpoint in a file that is common to multiple SWF files, fdb applies the breakpoint to all SWF files.

For example, suppose you have four SWF files loaded and each of those SWF files contains the same version of an ActionScript file, view.as. To set a breakpoint in the init() function of the view.as file, you need to set only a single breakpoint in one of the view.as files. When fdb encounters any of the init() functions, it triggers the break.