Troubleshooting

Troubleshooting

Flash CS4 ActionScript 3.0 Tutorial

 

How to Figure Out Why Your Flash ActionScript Won't Work

 

 

There are several troubleshooting techniques in Flash. Upon adding some new code, you may receive a error message. The message may help or it might confuse you even more.

Check Variable and Instance Names

It is easy to misspell a variable or instance name in your script or in the properties panel for instances.

Turn Off Specific Layers

If you suspect the problem is on a certain layer, you can always temporarily turn the layer into a Guide Layer. Guide Layers are not compiled in your swf file. For more information on Guide Layers, see topic, Adding a Guide Layer.

Comment Out Sections of Code

By placing Begin Comment (/*) and End Comment (*/) symbols around your suspected code, you can easily turn sections of code "on" and "off". You can also use the double slashes (//) if you only have a single line of ActionScript.

Add a Trace Statement

Trace statements allow you to see a variable's value at a specific point in the code. The example in this topic uses a trace() statement. For more information, see topic, Tracing.

ActionScript in Goofy Places

Whenever you place ActionScript on the timeline, a small "a" appears above the keyframe dot. If you see some extra a's, take a look at any rogue ActionScript.

Another way to see all the ActionScript that is connected to document keyframes is to open the ActionScript panel. With the panel open, the toolbox should display to the left of the code. If not, click the Show/Hide Toolbox icon at the top of the panel. In lower part of the toolbox, you can click on a specific keyframe and view any code connected to that keyframe.

 

Step One

Option double-click (PC - Alt double-click) the first keyframe of a new blank document to open the ActionScript panel.

Step Two

Copy/Paste the following code to the ActionScript panel. Test your movie by pressing Cmd/Return (PC - Ctrl/Enter).

var totalHere:Number = 1;

totalHear +=5;

trace(totalHere);

Step Three

The code in step two will not work until you fix the misspelled totalHear in the second line. Test your movie by pressing Cmd/Return (PC - Ctrl/Enter).

var totalHere:Number = 1;

totalHere +=5;

trace(totalHere);

Step Four

Comment out the trace() statement by adding two slashes before the word trace(). By turning it into a comment, the value is not displayed in the Output panel. Test your movie by pressing Cmd/Return (PC - Ctrl/Enter).

var totalHere:Number = 1;

totalHere +=5;

//trace(totalHere);

Dissecting the Code

The first line of the code establishes a number variable named totalHere and sets its initial value to 1. The second line adds 5 to the initial value. Now totalHere equals 1 + 5 = 6. The trace() statement displays the value of totalHere in the Output window.