Troubleshooting ActionScript > Authoring and troubleshooting guidelines

Authoring and troubleshooting guidelines

If you use good authoring practices when you write scripts, your movies will have fewer bugs (programming errors). You can use the following guidelines to help prevent problems and to fix them quickly when they do occur.


 
Using good authoring practices

It's a good idea to save multiple versions of your movie as you work. Choose File > Save As to save a version with a different name every half hour. You can use your version history to locate when a problem began by finding the most recent file without the problem. Using this approach, you'll always have a functioning version, even if one file gets corrupted.

Another important authoring practice is to test early, test often, and test on all target platforms to find problems as soon as they develop. Choose Control > Test Movie to run your movie in test-movie mode whenever you make a significant change or before saving a version. In test-movie mode, the movie runs in a version of the stand-alone player.

If your target audience will be viewing the movie on the Web, it's important to test the movie in a browser as well. In certain situations (for example, if you're developing an intranet site) you may know the browser and platform of your target audience. If you're developing for a Web site, however, test your movie in all browsers on all potential platforms.

It's a good idea to follow these authoring practices:

Use the trace action to send comments to the Output window. See Using trace.
Use the comment action to include instructional notes that appear only in the Actions panel. See Comments.
Use consistent naming conventions to identify elements in a script. For example, it's a good idea to avoid spaces in names. Start variable and function names with a lowercase letter and use a capital letter for each new word (myVariableName, myFunctionName). Start constructor function names with a capital letter (MyConstructorFunction). It's most important to pick a style that makes sense to you and use it consistently.
Use meaningful variable names that reflect what kind of information a variable contains. For example, a variable containing information about the last button pressed could be called lastButtonPressed. A name like foo would make it difficult to remember what the variable contains.
Use editable text fields in guide layers to track variable values as an alternative to using the Debugger.
Use the Movie Explorer in Edit-Movie Mode to view the display list and view all actions in a movie. See Using Flash. Flash Help
Use the for...in action to loop through the properties of movie clips, including child movie clips. You can use the for...in action with the trace action to send a list of properties to the Output window. See Repeating an action.


 
Using a troubleshooting checklist

As with every scripting environment, there are certain mistakes that scripters commonly make. The following list is a good place to start troubleshooting your movie:

Make sure you're in test-movie mode.
Only simple button and frame actions (for example, gotoAndPlay, and stop) will work in authoring mode. Choose Control > Enable Simple Frame Actions or choose Control > Enable Simple Buttons to enable these actions.
Make sure you do not have frame actions on multiple layers that conflict with each other.
If you're working with the Actions panel in Normal Mode, make sure your statement is set to expression.
If you are passing an expression in an action and haven't selected the Expression box, the value will be passed as a string. See Using operators to manipulate values in expressions.
Make sure multiple ActionScript elements do not have the same name.
It's a good idea to give every variable, function, object, and property a unique name. Local variables are exceptions, though: they only need to be unique within their scope and are often reused as counters. See Scoping a variable.

For more tips on troubleshooting a Flash movie, see the Flash Support Center.