|[ LiB ]|
A debugger is a special tool that programmers use to pinpoint errors, or bugs , in their programs. The Flash Debugger, like any debugger, helps you keep track of things such as function calls and variable values. In addition to tracking your program status, you can also set breakpoints . When you set a breakpoint, it means that you are telling the debugger to pause at a specific line of code when the program executes. By doing this, you can literally pause execution and check the status of all your variables and make sure everything is working properly; if the program isn't working properly, you can take the opportunity to correct the code. Where you set your breakpoints is up to you and where you think the bug is originating from.
A bug can be the result of careless programming or of forgetting something as simple as a curly bracket . As you expose yourself to ActionScript, you will learn to pick out the most common bugs and errors yourself and you will learn how to fix them on the spot.
Most of the time, you can get away with sprinkling trace statements all over the place to pinpoint your errors by output debugging information, but the truth is that sometimes even using the trace statement will be difficult. This is when you whip out the Flash Debugger.
Take a look at Figure 16.2; it shows GDA_PROG16.5.fla in the Debugger. To access the Debugger, instead of doing the usual of testing the movie, go to the Control menu and select Debug the Movie. The Debugger will open .
Every time you run the Flash Debugger, it will generate an SWD file that is stored in the same directory where you created your project. The file cannot be edited and is for internal use only. Don't get freaked out when you keep seeing the file regenerate itself after you've deleted it. It's not a Macromedia virus!
The right side of the Debugger panel allows you to select the code that you want to debug and set breakpoints. A breakpoint is a point in a program at which you want it to stop its execution so that you can inspect all its properties and variables.
The red Stop button over the code sets or removes a breakpoint from whatever line number you are on. See Figure 16.3 below so you can see how the Debugger indicates that a breakpoint was set by a small red stop sign to the left of the line number.
You can use the X button to stop debugging and continue execution. Once you are ready to test the program, you can just press the green Play button.
Once the program hits a breakpoint, it stops. You can then step into, step over, or step out of the breakpoint. This allows you to see what is happening in slow motion, so that you can trap errors that have been plaguing you. Figure 16.4 shows how the Debugger behaves when it hits a breakpointit turns the breakpoint icon into a small stop sign with a yellow arrow within. At this point, execution has stopped and is waiting for you to allow the program to continue after you perform your inspection on the program.
The box on the upper-left of the Debugger panel neatly organizes all of the global variables and Movie Clips (in layers ) so that you can easily select them and bring their properties up in the panels below.
The Stack pane helps you track what function the program is currently inwhen a function calls another function, you will be able to see this in the pane. The reason this feature was put into this Debugger is because you can follow variable values as they are passed through functions while following your game's execution accurately.
Now that you are familiar with the options in the panel, experiment with GDA_PROG16.5.fla and make sure you know how to step through it. Set breakpoints and step into them, then inspect the variables and make sure everything is going the way you want it. This light introduction to the Debugger will benefit you many timesso don't forget you now have a new resource you can use.
If you pick up any good habit from this book, please make it the art of neat programming. I promise that if you make layers on your Timeline for your graphics, comment your code, and name and separate your scenes, you've already won 90% of the battle.
|[ LiB ]|