Assigning Breakpoints


Perhaps one of the most useful features of the Debugger panel is the option to set and use breakpoints. A breakpoint is a position in your ActionScript code that halts playback of a movie while you are in Debug mode.

Using breakpoints, the Debugger panel enables you to step through a block of ActionScript line by line. You can define when the Flash movie will halt and when it will proceed. You can choose to execute a function or to step through the function. Choosing to step through a function will halt your movie on every line of the function waiting for your action. This is very valuable and makes it easier to find (often simple) problems in your ActionScript.

On the CD-ROM 

You can find the debugging_code.fla file in the ch32 folder of this book's CD-ROM. Make a copy of this file to a location on your hard drive. This file is used in the next few sections.

Adding or Removing Breakpoints in the Actions Panel

You can set, delete, or remove all breakpoints in the Actions panel while authoring a Flash document.

Follow these steps to apply a breakpoint to a specific line of ActionScript code:

  1. Open the debugging_code_nobreaks.fla document.

  2. Select frame 2 of the actions layer, and open the Actions panel (F9, or Option+F9 on Mac).

  3. Place the cursor on line 18. The Debugger stops the movie at a line where a breakpoint exists, only executing the code before the breakpoint. Breakpoints should be positioned on lines where you think an error exists or just before the point where you think an error is occurring.

  4. Do one of the following:

    • Click the gutter to the left of the line number.

    • Click the Debug Options button in the toolbar of the Actions panel (look for the stethoscope icon), and from its menu choose Set Breakpoint.

    • Right-click (Windows) or Control+click (Mac) the line of code and select Set Breakpoint. A red dot in the gutter indicates lines that have breakpoints, as shown in Figure 32-8.

image from book
Figure 32-8: You can see the breakpoint icon residing in the gutter of the Actions panel.

Perform the following steps to delete a breakpoint from a line of code in the Actions panel:

  1. Place the cursor on the line where a breakpoint exists.

  2. Do one of the following:

    • Click the Debug Options button and choose Remove Breakpoint.

    • Right-click (Windows) or Control+click (Mac) and select Remove Breakpoint.

    • Simply click the red dot in the gutter area.

    The red dot will be removed.

Tip 

To remove all breakpoints from the code, follow Steps 1 and 2 and select Remove All Breakpoints instead of Remove Breakpoint.

New Feature 

If you edit ActionScript files (.as) in Flash Professional 8, you can now add breakpoints within the file.

Adding and Removing Breakpoints in the Debugger Panel

Once you have started debugging your movie, you can add and remove breakpoints. You can remove a single breakpoint or remove all breakpoints.

Follow these steps to add a breakpoint in the Debugger panel:

  1. Open a fresh copy of the debugging_code.fla document from this book's CD-ROM.

  2. Select frame 2 of the actions layer.

  3. Enter Debug mode by choosing Control Debug Movie.

  4. Before you press the Continue button on the Debugger panel, choose the actions for frame 2 from the drop-down menu below the toolbar of the Debugger panel. You should see the ActionScript code from frame 2 of the actions layer displayed.

  5. Place a cursor on line 12.

  6. Do one of the following:

    • Click the gutter area to the left of the line number.

    • Click the Toggle Breakpoint button in the toolbar of the Debugger, which will add a breakpoint if none exists on that line. (It will remove a previously defined breakpoint if one exists.)

    • Right-click (Windows) or Control-click (Mac) and select Set Breakpoint.

    When the debugger reaches the line where you placed the breakpoint, it halts playback of the movie, waiting for your response.

  7. Once the breakpoint is set, click the Continue button. The debugger pauses the movie when the code execution reaches your breakpoint. When the breakpoint is reached, you can analyze various aspects of the movie in the Variables, Properties, and Watch tabs of the Debugger panel. You need to click the Continue button to resume playback of the movie.

To remove a breakpoint in the Debugger panel, follow these steps. This example continues from above. You should use the same file, so make sure you are still in Debug Movie mode.

  1. Place the cursor on line 12.

  2. Do one of the following:

    • Click the red dot of the breakpoint in the gutter area.

    • Click the Toggle Breakpoint button, which removes the breakpoint. If you push it a second time, the breakpoint will be re-set.

    • Right-click (Windows) or Control+click (Mac) and select Remove Breakpoint.

Caution 

Changes you apply to breakpoints while using the Debugger panel in Debug Movie mode only exist for that debugging session. When you return to authoring mode, the breakpoints you added (or removed) during the debugging session will not be saved.

Stepping through Your Code

Using breakpoints and the Debugger panel, you can step through lines of your code while the movie is playing. This is a very powerful feature, enabling you to pinpoint the exact position of a problem in your code.

When you start a debugging session by choosing Control Debug Movie, the movie is paused in the Flash Player so you can modify and set new breakpoints before you start the debugging session. You need to push the Continue button to enable your movie to play.

On the CD-ROM 

Make a copy of the debugging_breakpoints.fla document from the ch32 folder of this book's CD-ROM.

  1. Open the debugging_breakpoints.fla document. We built the ActionScript in this movie to demonstrate the process of stepping through lines of code.

  2. Debug the movie by choosing Control Debug Movie.

  3. As the movie is initially paused, click the Continue button to start debugging. Refer to Figure 32-7 to easily locate the Continue button.

  4. When the Debugger panel reaches the first breakpoint at the line mcTest.onEnterFrame = function (), it will stop and wait for you to choose an action. The little yellow arrow in the gutter indicates the current position of the movie.

    You can choose one of the following actions:

    • Step Out: If you are debugging inside a user-defined function, Step Out will cause the debugger to execute everything within the function and continue playing, until it reaches the next breakpoint outside of the function. However, if there is a breakpoint below the line where you have selected Step Out within the function, the debugger will halt the movie and wait for your action.

      Note 

      If you click Step Out on a line that is not inside a function, it performs the same actions as if you had clicked Continue.

    • Step In: If you position a breakpoint on a line where a function is called, such as line 22 in frame 2 on the actions layer of debugging_code.fla, the debugger will move to line 4 — the first line within the function you "stepped into." Click Step In to proceed to the next line in the function. Clicking Step In within a function will proceed and pause the movie to the next line, regardless of whether it has a breakpoint. Click Continue to move through the lines until another breakpoint is reached, skipping lines without one.

      Note 

      If you click Step In on a line that is outside of a function, it performs the same action as if you had clicked Continue.

    • Step Over: Clicking Step Over on a breakpoint tells the Debugger to ignore the line of code where the breakpoint occurs and moves the player to the next line of your code. If you choose Step Over on a line where a function is called, it moves to the next line and calls the function in the process.

      Note 

      If you click Step Over on a line where a function is called and the function has a breakpoint inside of it, the Debugger will halt the movie at the breakpoint line.

    • Continue: Choosing Continue will start the movie playing until the next breakpoint is reached.

    • Stop Debugging: Selecting this option will stop the Debugger from processing the actions any further. However, your movie will still continue to play.

    • Toggle Breakpoint: If you click this button, it will turn the breakpoint off because one already exists on that line. You will need to click either Continue or Step In to advance the movie. However, the Debugger will not halt the movie at this line again as the breakpoint has been removed. Pressing Toggle Breakpoint a second time will set a breakpoint.




Macromedia Flash 8 Bible
Macromedia Flash8 Bible
ISBN: 0471746762
EAN: 2147483647
Year: 2006
Pages: 395

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net