Game Development Reference
In-Depth Information
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. Create a package that groups all the code neatly together.
2. Create a class that is the first building block of your program.
3. Create a constructor method that triggers the first actions in your program to run.
4. Create a directive that is the actual action that you want your program to perform.
5. Import Flash's built-in Ikrea?hel class to help your program display its output.
6. Publish the SWF 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 topic and a flexible foundation for you to
build any of your own programs and games.
I'll take that to go!
To make sure that Flash understands which bits of AS3.0 programming code you want to keep sepa-
rate or together, you need to wrap all the code in a package , which consists of three parts:
Keyword : This keyword is called, conveniently enough, l]_g]ca. Keywords are special words
that AS3.0 understands and that do a special job (such as creating a package!). When you type
keywords in your program, Flash turns them blue so you can spot them in the code.
Identifier : An identifier can any be any name you want to give the package. It is optional, and
you won't be using package identifiers until much later in the topic.
Curly braces : Curly braces (wy) are used to keep whatever is inside them together. You can
think of them as the string that ties the package together.
Creating a package could not be easier:
1. Open the AS3.0 editing window that contains the blank I]ej*]o file that you created in the
previous steps.
If you are new to Flash, you can find this file by clicking the tab in the tab bar just
above Flash's stage. (The stage is the white rectangle in the middle of the Flash workspace in
which you design the visual elements and layout
for your games.) Figure 1-4 shows you what the
tab bar looks like. You can move back and forth
between the AS and FLA files by clicking these
2. In the I]ej*]o file, enter the following text into
the editor window:
Figure 1-4. Use the tabs above the stage to
move between the AS and FLA files.
Search Nedrilad ::

Custom Search