Director MX Debugging Tools

In Director MX, bugs inevitably appear as error messages. Figure 19.7 is an example of this. A button has been clicked and the error message box appears. The important items in this dialog box are the Debug button and the Script button.

Figure 19.7. A typical error message in Director MX shows you the error and the Script and Debug buttons.

graphics/19fig07.gif

In addition to the Script and Debug windows, you also have available to you the Compile button in the Script window, the watcher, and the Message window.

Using the Director MX Debugger

If ever there was a feature in Director MX that will trip up the "newbie," it has to be this one. Up pops the error, and the first reaction is to click the Debug button in the mistaken assumption that Director will somehow fix the code. It won't happen. The purpose of the Debug window is to show you where the problem occurred and nothing more.

There are actually two occasions where the Debugger is an invaluable tool. The first is when you get an error message. The second is when you need to set a breakpoint. Follow these steps to use the Debug button:

  1. Open the Button1.dir file in the Chapter 19 Exercise folder downloaded from the book's site. Play the movie and click the button.

  2. When the error message appears, click the Debug button to open the Debugger. Another method for opening the Debugger is to set a breakpoint in the code. Setting a break point in the code causes the movie to stop and the Debugger window to open when the line of code containing the break point is executed.

    The Debugger shown in Figure 19.8 is not as intimidating as it seems.

    Figure 19.8. The Director Debugger shows you the line of code where the error occurred.

    graphics/19fig08.gif

    As you can see, the Debugger is essentially divided into four areas. On the left side of the page from top to bottom are the following three panes:

    • Call Stack Pane: This shows the sequence of handlers that ran before the error.

    • Variable Pane: This shows all the variables associated with the handler.

    • Watcher Pane: This shows the values and data in the handler and tracks their values.

    On the right side of the window is the Script Pane. The green arrow points to the line of code where the script started executing.

    In the case of our line of code, it reads:

    sprite (the clickOn).memberNum = sprite (the clikOn).memberNum+1
    

    It stopped on that line because of a common error?a spelling problem. The mouse property "the clickOn" is spelled incorrectly.

  3. Click the mouse between the "i" and the "k" in the second reference to "the clikOn" and enter a lowercase "c." Close the Debugger.

  4. Rewind and play the movie. The button will change color, and the error window is a thing of the past. Select File, Revert because we are now going to show you how to avoid this problem in the first place.

Note

We can hear the veteran Director MX developers sighing and saying, "Oh man." We agree; using the Debugger for such a simple error is overkill. This feature really shines when variable values and handlers are being used for some rather complex coding.


Using the Script Window

The Script Window is where scripts are entered in Director MX. When you click the button to get the error message, you will notice the Script Error window not only tells you it can't find a Property, it shows you the line of code and the Property?#clickOn?that couldn't be found.

In this instance, click the Script button because you are dealing with a spelling error. Follow these steps to fix the problem in the Script window:

  1. Play the movie and click the button on the stage.

  2. Click the Script button in the Script error window to open the Script window shown in Figure 19.9.

    Figure 19.9. The Director MX Script window is where scripts containing rather obvious errors can be changed.

    graphics/19fig09.gif

  3. Add the missing "c" to the word "clikOn."

  4. Close the script window, play the movie, and click the button on the stage. It changes color.

Tip

A very common coding error is a spelling mistake. These usually result in an error that tells you a variable doesn't have a value. A good habit to get into is to compile the script before closing the Script window. The Compile button is on the Button bar and looks like a lightning bolt. When the script is finished, click it, and if there is a problem, you will see an error message like that shown in Figure 19.10. In this instance, a space was added between "mouse" and "Up."

Figure 19.10. Clicking the Compile button?the lightning bolt?before saving the script will catch syntax errors.

graphics/19fig10.jpg