Lesson 1: Game Setup

Part 1: Setting Up Your .fla File

To begin with, you will need to know how to set-up your .fla file for maximum efficiency when designing and programming your game. I’ve found that the best strategy for this is as follows:

1. Choose a sensible layer and frame strategy

1.1 Choose a sensible layer and frame strategy

For this game we will use as few frames as possible. In fact, the actual game will only use one frame in Flash (”Game”). However, we will want to make sure the timeline is as clear as possible to develop and maintain the code in the game.

Layers:

Labels: This layer is used to place any “jump” labels” that you will use for your game .fla. We will try avoid this for any actual game logic, but for they will be necessary for easy integration of services like Mochiads, Mochibot, and a logo screen.

Code: You should always only have one layer in a Flash movie that contains ActionScript. Otherwise, it will be very difficult to find code that is spread all around the Flash movie.

Assets: Any and all movie clips, graphics, buttons, etc. should go on the layers below the top two. The Assets layer above if for “exported assets” which I will explain a bit later.

2. Put as much code as possible in external .as files

It is much easier to maintain a Flash game that used external .as files for most the code, and for one that uses any sort of Object-Oriented structure, it is vital. For Lesson 1 we will have the following .as files: HomeWars.as, Player.as, Missile.as, TitleScreen.as, EndScreen.as. In subsequent lessons we will add even more. Each .as file for our game holds a seperate object oriented class that will be used to create the game.

3. Set your game to at least 31 frames per second (FPS)

31 FPS is the bare minimum for games in Flash. 30+ FPS will give your games a smooth feel, and it will allow your code enough cycles to process movement, hits, etc properly. However, this must be followed-up with efficient code. However, no matter how many FPS you select, you must write code that is efficient enough to actually allow for that many FPS. It does not matter how high you set your FPS if the processor is pegged at 100% while your game is running.The setting is flash is what the player will “attempt” to run the game at, but there are no guarantees.

4. Use folders in your library

1.4 - Use folders in your library

You should always attempt to organize your Flash assets in your library in some way that will make them easy to find when you need to update them, make code changes, or debug your game. I like to use the structure above. No matter how you organize your library though, be sure it makes sense to you.

The organization of the library is not only a “nice to have,” it should reflect the object-oriented structure of your code. You will notice that the Object folder above contains a series of MovieClips that all start with the letter “F” and all say something like “Export:Fxxx” in the Linkage column. All of the objects in this folder are associated with an ActionScript class.

Let’s take a closer look at the FPlayer MovieClip. By right-clicking (CTRL-click on Mac) the MovieClip in the library, and clicking the “properties” option you will see a dialog box similar to the following:

1.4 - Symbol properties box

In the Linkage section, you will see:

  • Identifer. This is the name we will use in our code to create an instance of one of these objects.
  • AS 2.0 Class. This is the object class that will hold all the code and properties for this object. The convention is to name your .as file the same as your class name, so the Player class would be in an external .as file name Player.as .
  • Linkage check boxes. Make sure that Export For ActionScript is checked. This allows use make use of this object in our code. However, also notice that Export In First Frame is not checked. This is also not the default behavior in Flash. Having this unchecked means that it will be necessary to include an instance of this object in a frame somewhere before we use it. While that might seem like a small burden, the benefits outweigh it. It is necessary to un-check Export In First Frame if you want any kind of pre loader counter or loading bar to work properly in your game. We will do something similar for any sounds and music we use in the game.

Now, remember the set-up of our frames?
1.1 Choose a sensible layer and frame strategy

Notice the “Assets” label on Frame 17. This is where we will place all of our exported assets. We will use a simple “gotoAndStop("Game")” from the Preloader frame to jump-over this frame, so it is never seen in the game. However, it will serve our purposes, allowing for all exported assets to be available before they are needed, but after the preloader does it’s preloading magic

On the assets layer on Frame 17, you will see what looks like a mess:
1.4 - Assets label on frame 17

This contains one of each object we will be using in the game. The look of this frame does not matter because, again, no one will ever see it, but its function is vital.

Read the rest of the series: ‘Anatomy of a Flash Game’

  1. Anatomy of a Flash Game: Lesson 1 – Setting up the game
  2. Anatomy of a Flash Game: Lesson 2 – Creating Enemies & The Game Environment
  3. Anatomy of a Flash Game: Lesson 3 – MochiAds, MochiBot and MochiAds Leaderboards