tip: actionscript 2.0

With ActionScript 1.0, we could just start using variables on the fly, without formally declaring them. ActionScript 2.0 is more fussy.

So if you are using some ActionScript from this book (or from any number of nice online tutorials from other people as well), and you're getting some crazy error message, the first thing to try is this:

  • File menu > Publish Settings
  • Under the Flash tab, select ActionScript 1.0 instead of 2.0 from the menu.
  • Save your file and test it.

A different change in your FLA that may solve your problem just as well (especially if the script is pretty simple):

Say you are using a variable named n. The first time you use n in the movie, it's just n. Maybe it's n++ ... maybe it's n = "Mary" or n = 27.

But nowhere in the movie was n ever declared -- with the word var in front of it.

If that's the case for you, then on frame 1 in the Timeline (not on your button! You cannot declare a variable on a button), type this ActionScript:

var n;

If (and only if) n has a numerical value, type this INSTEAD:

var n = 0;

You may use another numeral, if that makes sense in your movie. It's especially important to realize that ActionScript 2.0 "types" variables; that is, the variable will be a number, or a string (text), but it can't be both.

And by the way -- NaN means "not a number." So when your error message says NaN, this variable business is probably at the root of your trouble.

> More tips