Coding in Flash
Errors and debugging
Errors are inevitable even for seasoned programmers.There are several types of errors mostly falling into two categories. The first are syntax errors. They are usually misspelled keywords, variable names, adding or forgetting symbols like dots or semicolons where it’s not allowed, not matching parameters for the functions and so on. The program simply won’t run if there is any syntax error in the code. In Flash case you could not compile SWF file if syntax error appeared.
The second type is logical errors. They do not prevent your code from compiling, but you program works in the wrong unexpected way. For example you click button to switch to the Frame 14, and program stops instead. Logical errors are not so annoying as syntax but sometimes it’s more difficult to fix them.
You may expect numerous errors when you start working with the new computer language. Stay calm – it’s happen to everybody. Persistence and attentiveness are among the most valuable programmers’ personal characteristics. Luckily Flash offers some tools to help with correct code writing.
We’ve mentioned “tips” - matching capabilities for manual coding. If Actions Panel recognizes the code it tries to help the programmer with available coding options.
It may happened to you – after you entered the erroneous code and tried to Test Movie or Publish Movie – the Output window appears by itself and information about error is displayed. It gives you a possible reason of the mistake and line of the code where it happened. To make it more useful – be sure that you have checked a “Display Line Number” in the Normal/Expert Mode switcher.
Also in Expert mode above Code window you may find a button with a “check” icon. If you click it the code syntax will be checked before you’ve published it.
There are more debugging techniques in Flash – it’s possible to place a breakpoint at the certain line of the code and pause it there. Also it is possible to watch the value of the variable if it changes constantly along the code execution. As our code will be fairly short we unlikely will use those techniques.
Remember one thing that is responsible for so many errors – ACTIONSCRIPT IS CASE SENSITIVE!
It means that if, If, iF and IF are different words in ActionScript. And only the first may serve as a valid keyword.