Debugging in Flash MX 2004

You can't avoid using ActionScript when it comes to using Flash MX 2004 with dynamic sites. When you start using code, you will inevitably make mistakes and have to debug the script to isolate them. Debugging, regardless of the application, requires patience, doggedness, and meticulous attention to detail.

The biggest mistake you can make is to have the people testing the movie report bugs to you in a vague manner. A report along the lines of, "I was using the movie, and after 19 minutes, the screen froze," is totally useless. Take a page from the software manufacturers and document the bugs . This usually takes the form of a step-by-step procedure to replicate the bug. A typical report would be:

  1. Click on the date input field.

  2. Enter today's date.

  3. Click OK.

    • Result: The temperature in degrees Kelvin appears in the field.

    • Expected result: Today's date should appear in the field.

Flash MX 2004 contains the following debugging tools:

  • The trace() function.

  • The Debugger.

  • The List Variables menu.

  • The List Objects menus .

Using the Trace Function

The most ubiquitous tool is the trace function. The function simply accepts an argument and puts the results in the Output window. To invoke it, choose Window, Developer Panels, Output, or press the F2 key. A typical trace function would be:

 Trace("Hey Chris"); 

In this instance, the phrase, "Hey Chris" would appear in the Output window.

Another would be:

 var x = 2; trace(x); 

In this instance, the value "2" would appear.

Use this function to trace values of variables used in the code. Also keep in mind that trace only works in test mode. It will not work in a browser.

Tip

Before you export your final .swf file, be sure to click the Flash tab in the Publish Settings (File, Publish). When the Flash Publish window appears, as in Figure 19.11, make sure you check Omit Trace Actions. This prevents the trace function from actually going into the final .swf file.

Figure 19.11. Be sure to turn off the trace actions before you publish the Flash .swf file.

graphics/19fig11.jpg


The Flash MX 2004 Debug Panel

The Debug panel (see Figure 19.12), available through Control, Debug Movie, Command-Shift-Return (Mac), or Control-Shift-Enter (PC), launches the .swf file. Here are just some of things this panel can do while the movie is running:

  • Show you the movie clip structure of a movie.

  • View and modify variables.

  • Like Director MX, keep track of the currently running function and what functions were called to that point using the call stack.

  • Add or remove breakpoints to the code. This will enable you to "step" through the movie.

Figure 19.12. The Flash Debug panel can only be accessed through the Control menu.

graphics/19fig12.gif

When the Debug panel is open , the Flash MX 2004 menu will change to include a Debug menu item.

As you can see, the panel is divided into four areas. On the left side of the panel are:

  • Movie Clip Tree View: This area shows you the hierarchy of the movie clips and objects on the stage.

  • Properties, Variables, Locals, Watch: These four tabs enable you to see all the properties, objects, and variables in the movie. Click the Properties tab, and a list of the selected object or movie clip's properties are listed. Click the variables tab to see a list of the variables in the movie. The Locals tab enables you to see the values of your local variables at the current point in the movie. For example, if you set a breakpoint in a function, the Locals tab would show you all the local variables inside the function. The Watch tab enables you to see a subset of the variables and properties from the other tabs. This is usually done by right-clicking (PC) or Control-clicking (Mac) an item and selecting "watch" from the Context menu.

  • Call Stack: This shows you the functions that are running and the functions that started them.

    The right side of the panel gives you access to the code and the ability to add (The Stop Sign) break points or remove them by selecting the Stop sign a second time.



Building Dynamic Websites with Macromedia Studio MX 2004
Building Dynamic Web Sites with Macromedia Studio MX 2004
ISBN: 0735713766
EAN: 2147483647
Year: 2005
Pages: 158

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