The Output Panel


This important panel has nothing to do with your published final movie. Instead, it is a tool to use while developing and testing your movie. The Output panel serves two important purposes. First, when you test your movie, if any of your script contains syntax errors, these errors, along with their corresponding line number in the script, are displayed in the Output panel. The second use of the Output panel is as a way for your script to display information to you when the movie is running. This can be useful when you are trying to uncover logical errors in your scripts. Let's take a look at both of these important features of the Output panel.

Syntax Error Reports

You will encounter two kinds of errors when you're programming in any language: syntax errors and logic errors. The former is by far the easiest to deal with because Flash knows when you make a syntax error. This is the type of error we're concerned with here. A syntax error happens when you type in some script that Flash does not understand. If you type a [ where you should have typed a ( or you forget to put a } at the end of some script, Flash becomes confused and displays an error message, a path , and a line number in the Output panel. Let's create a syntax error now so that you can see what this looks like.

Caution  

In addition to syntax errors, you will also make logical errors, where Flash understands exactly what you are telling it in your script but your script does not tell Flash to do the right thing. In contrast to syntax errors, Flash says nothing about logic errors. It leaves your movie with some kind of improper behavior.

Create a new movie, select the first frame, and enter the following script into the Actions panel:

 onClipEvent(enterFrame){} 

Now open the Output panel and test your movie. You should see something that looks Figure 2.6 in the Output panel.

click to expand
Figure 2.6: The Output panel alerts you to syntax errors in your scripts.

The first four pieces of information tell us where the offending script is located. In this case, our error occurs on line 1 of frame 1 of layer 1 of scene 1. Following that is a description of the error, which in this case is Clip events are permitted only for movie clip instances . This message essentially informs you that you are trying to attach a movie clip event handler to something other than a movie clip instance ”in this case, a frame. Because you can't use movie clip event handlers in a frame script, this action is illegal and confuses Flash. The final piece of information displayed is the actual line of offending script.

Tip  

To determine what line you are on in a given script if you don't have line numbers turned on, look at the bottom of the Actions panel, which lists the line number for your reference.

Tip  

When you encounter multiple syntax errors being reported , disregard all but the first. Find and fix this first error and then test again. Many times, errors that are listed after the first are not really errors ”they are simply the product of Flash's confusion over the first error.

The trace Function

You will often want to send messages to yourself while you test your movies. Many errors become clear when you are able to use messages to trace through the actual flow of scripts in your movie, and that's what the trace function is for.

Although we have not formally discussed functions yet and won't until Chapter 3, "Programming Interactivity: Mouse Chaser ," the use of trace should be simple enough not to require it. This simple usage is best demonstrated with an example.

Create a new movie, select the first frame, and add the following script:

 trace("hello!"); 

Now test the movie and watch the Output panel. You should see the word hello! printed one time, as in Figure 2.7.

click to expand
Figure 2.7: You can use the trace function to print messages to the Output panel during movie testing.

Remember that single frame timelines do not loop, so hello! is only printed once. If you add another frame to the main movie timeline, you should see the word hello! flood your Output panel during testing, as in Figure 2.8.


Figure 2.8: If you print something every frame, your Output panel becomes flooded with text.

I could go on about the trace function, but we're not ready for that yet. So far, we've managed to write some ActionScript and get some simple behaviors out of Flash without talking about programming in general, but we're running out of things we can do without discussing some of the goodies that exist in all programming languages. Now it's time for a look at the general programming concepts used in ActionScript.




Macromedia Flash MX 2004 Game Programming
Macromedia Flash MX 2004 Game Programming (Premier Press Game Development)
ISBN: 1592000363
EAN: 2147483647
Year: 2004
Pages: 161

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net