Your First Program

[ LiB ]

You've waited a long time for this momentand here it is. You're about to set up and produce your very first program.

Open up Flash and create a new movie project by going to File, New. You should now have a blank stage ready. Along with the blank stage, notice the blank keyframe on the first (and only) layer.

Right-click on the first frame that's on the first layer; the pop-up menu shown in Figure 3.9 will open. Select Actions from the menu. If you don't have a right mouse button (as on Mac OS systems), you can select the frame and press F9 to access the Actions Panel.

Figure 3.9. The Timeline's pop-up menu

graphic/03fig09.gif


Type in the trace command as so:

 trace("My first ActionScript program!"); 

Close the Actions Panel. Save the file as something friendly like Exercise3-1.fla. Access the Control, Test Movie menu item and you should get an Output window like the one in Figure 3.10.

Figure 3.10. Your first output

graphic/03fig10.gif


NOTE

NOTE

You should be aware of one thing.The contents of the Output window can only be viewed from inside the Flash development environment. It cannot be viewed from the Flash Player.

Now that you have your first program up and running, let's get more acquainted with the Actions Panel. I'm going to show you how to check your syntax so that Flash doesn't complain when you try to run the program.

Go back to your main Timeline by closing out the Output Window. Make sure you're back at the Actions Panel. If you are not there, press F9 to access the panel. You're going to mess up your program, on purpose, just to get familiar with the way in which Flash complains.

Type in the following linenotice that it is the same line as the program you typed in before, except that it's missing a closing parenthesis:

 trace("My first ActionScript program!"; 

Go to Control, Test Movie and watch Flash complain in that same Output Window. You should get a message similar to Figure 3.11.

Figure 3.11. Syntax errors were found

graphic/03fig11.gif


Before you go on and decipher what Flash is trying to communicate to you, let me show you how to check your syntax before running the program. Go ahead and click on the Check Syntax button on the Actions Panel. Check out Figure 3.12 to see right where it's located.

Figure 3.12. The Check Syntax button

graphic/03fig12.gif


Once you press the Check Syntax button, you'll get the message box shown in Figure 3.13.

Figure 3.13. Flash has found an error.

graphic/03fig13.gif


You will also find that the Output Window pop-up contains the same information you saw in Figure 3.11. In the Output Window, the first part of the message tells you exactly where Flash encountered the problem. In this situation, it goes like this:

 Scene=Scene 1, Layer=Layer 1, Frame=1: Line 1: 

Flash can have many scenes in a movie project, so first it tells you the name of the scene you are working in. By default, Scene 1 is the name of the only scene in the file.

Flash also tells you what layer the script was on. Our only layernamed Layer 1 by defaultis where our script lies.

Our great program gets even more specific and tells us what frame the error was encountered on. It was Frame 1.

The problem was with the first line of the scriptas the error told us. The piece that comes after this tells us what Flash expected to be or not to be there. Let's see what it said:

 ')' or ',' expected 

Here, you can see that Flash is complaining about a missing closing parenthesis or a comma. Check the line you typedyou'll notice that a comma isn't needed anywhere . You're missing a closing parenthesis. Put it back in where it should goright before the semi- colon .

 trace("My first ActionScript program!"); 

Press the Check Syntax button now. You should get the pleasant message box shown in Figure 3.14.

Figure 3.14. No errors found in the script.

graphic/03fig14.gif


You can now go ahead and run the program with confidence.

You've just created your first program and debugged it. It's true that the program you created in this section is not visually stimulating, but hey, you did it! Make sure you understand the whole process before moving on to the next section.

[ LiB ]


Game Development with ActionScript
Game Development with ActionScript
ISBN: 1592001106
EAN: 2147483647
Year: 2004
Pages: 162
Authors: Lewis Moronta

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