Foundation Game Design with ActionScript 3.0, Second Edition (5 page)

Figure 1-9.
Area for writing code

This is where you will be writing all you computer code. Flash Builder has automatically filled this box with some computer code that it thinks might be a useful place for you to start. It actually is, but for the purposes of learning, I'm going to ask you to delete all of it so that you can start with a completely blank slate.

Select all the text in the code editing window, as shown in
Figure 1-10
.

Figure 1-10.
Select the canned code

Delete all of it so that the window is completely empty, as shown in
Figure 1-11
.

Figure 1-11.
Completely blank code editing window

You now have a completely blank code editing window. This is where you will write your first computer program.

Next, you need to make a small change to Flash Builder's configuration to tell it to run your program directly in the Flash Player window, not the web browser.

Telling Flash Builder to run your programs in the Flash Player

When you create games with Flash Builder, it takes the programming code that you write in the editor window and plays it in the Flash Player software. The Flash Player software was installed on your computer automatically when you installed Flash Builder. However, when you first install Flash Builder, it's set up so that it runs the Flash Player inside a web browser. This is a slow and inefficient because every time you test your game you'll have wait for a browser window to pop open. It's much better if Flash Builder runs your game directly inside the Flash Player window. Fortunately, this is very easy to set up by making a small change to Flash Builder's configuration.

1. Select Project
Properties from Flash Builder's main menu at the top of the screen, as shown in
Figure 1-12
.

Figure 1-12.
Select the Properties option

2. A new Project Properties window will open. Select ActionScript Compiler from the menu on the left, and you should see the options appear on the right, as shown in
Figure 1-13
.

Figure 1-13.
ActionScript Complier options

3. Find the HTML wrapper section near the bottom of this screen. Uncheck the option called Generate HTML wrapper file. It should now look like
Figure 1-14
.

Figure 1-14.
Don't generate a HTML wrapper file

This is the option that automatically opens your game in a web browser. By unchecking it, Flash Builder will open your game directly in the Flash Player.

4. Select the OK button to save this change.

You're now ready to write your first AS3.0 computer program!

Writing your first program

You now have most of the pieces in place to begin writing your first program. In the next few steps, you'll do the following:

  1. Learn how to make ActionScript files with the .as file extension.
  2. Create a package that groups all the code neatly together.
  3. Import graphics capabilities that you'll need to display text and images.
  4. Create a class that is the first building block of your program.
  5. Create a constructor method that triggers the first actions in your program to run.
  6. Create a directive that is the actual action that you want your program to perform.
  7. Import Flash's built-in Sprite class to help your program display its output.
  8. Publish the finished Flash file to see the actual output of all your hard work.

This process might seem like a lot of work, but at the end of it you'll have a complete system in place that will form the basis for all the projects in the rest of the book and a flexible foundation for you to build your own programs and games.

ActionScript files and the .as file extension

An ActionScript computer program is what controls your entire game. It tells all the game characters and elements exactly how they should behave. ActionScript programs are the most important components of a game, and most of this book is devoted to explaining how to write and understand them.

An ActionScript program is nothing more than a text file containing special words and characters. When you write an ActionScript computer program, you're just creating a simple text file on your computer with a
.as
extension. Files with a .as extension are known as ActionScript files or AS files.

You can see this in Flash Builder by looking at the top of the code editing window. If you've followed the instructions in this chapter, the highlighted tab bar at the top of the code editing window will read HelloWorld.as.
Figure 1-15
shows what this looks like.

Figure 1-15.
The highlighted tab bar at the top of the code editing window in Flash Builder tells you that you are creating an ActionScript file with a .as extension.

Look to the left of the code editing window and you'll find the Package Explorer, as shown in
Figure 1-16
. The HelloWorld.as file will be highlighted.

Figure 1-16.
The Package Explorer shows you which files and folders are being used in your project.

Other books

Kid Calhoun by Joan Johnston
Bridge of Sighs by Richard Russo
From the Moment We Met by Adair, Marina
Split Decision by Belle Payton
Goated by the Gods by Sheri Lyn
Spell Robbers by Matthew J. Kirby
Unknown by Unknown
Watch Me by Brenda Novak