Beginning Flash and ActionScript Game Programming Part 2: Downloading and Setting Up FlashDevelop and Compiling Your First Program

In the previous section, I listed pros and cons of creating games in ActionScript, as well as useful terms you may encounter when programming in ActionScript.

In this section, we will download and install FlashDevelop, and Create our first program.

Downloading and Installing FlashDevelop

The first step to starting to program is to download FlashDevelop from here: http://www.flashdevelop.org/community/viewforum.php?f=11

Click on the latest version on the top then scroll to the bottom of the next page and click on the link to begin downloading.
The file will download, click on it to run it and start installing FlashDevelop.
Just keep clicking ‘Next’ until it is installed, or customize anything you want (like removing quick launch link).
It will download the latest Flex SDK as it is installing, which saves a step over previous versions. In the past, you had to download it yourself, and link to it, but now it is super easy.

After it is installed, go to your start menu, and launch FlashDevelop.
Once it loads, click on ‘Project->New Project’, and select ‘AS3 Project’. Give it a name of ‘My First Game’, and select ‘create directory for project. Point the location to where ever you want, and click ‘OK’.
Now you should see the screen split into 2 parts- the left side is for your code, and the right side has all of your files in your project directory, with the top folder names ‘My First Game’.
Make sure that is open(by seeing folders under it) by double clicking on it if you don’t see the sub-folders.

Next, double click ‘src’, and double ‘Main.as’, which should show up under it. All of your code / source files need to go inside of this ‘src’ folder.

The left half of your screen should now display something like this:

Main.as

package
{
	import flash.display.Sprite;
	import flash.events.Event;

	/**
	 * ...
	 * @author Chris
	 */
	public class Main extends Sprite
	{

		public function Main():void
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}

		private function init(e:Event = null):void
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			// entry point
		}
	}
}

If you hit the CTRL key plus the Enter Key at the same time (Ctrl+Enter), it should build and compile your first program and bring up a white window!

This compiles the code in that file into a swf file and places it in your folders ‘Bin’ folder.

But lets make it output something when it runs. Under ‘//entry point’, create a new line (press enter key) and type:
‘trace(“This is my First Game!”);’

So your file should now look like:

Main.as

package
{
	import flash.display.Sprite;
	import flash.events.Event;

	/**
	 * ...
	 * @author Chris
	 */
	public class Main extends Sprite
	{

		public function Main():void
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}

		private function init(e:Event = null):void
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			// entry point
			trace("This is my First Game!");
		}
	}
}

If you compile this now, it will still show a blank window, but in the bottom below your code, you should see at the end of the output:

‘Done(0)
[Starting debug session with FDB]
This is my First Game!’

Trace is used to ‘debug’ your program- you can output text, variable values, and can check to make sure you can see what is happening in your program.
The end user can’t see these outputs, it only shows up while running inside of FlashDevelop (with the default configuration of ‘Debug’).

Commenting

When you want to make a note in your code, but don’t want it to affect your program, you use commenting.

There are two ways to comment, the first is used to comment out the whole line. Use ‘//’, two forward slashes, and it will comment out everythign afterwards on that line.
You can see that being used above for ‘//entry point’. The two forward slashes are looked at by the compiler, realizes that it is not code that needs to be compiled, and skips the rest of the line.

The second way is able to comment out multiple lines, or a big block of code. Start it by using ‘/*’ (forward slash and a asterick), and end it using ‘*/’ (asterick and a forward slash).
An example of this can be seen above around the lines enclosing the ‘@author Chris’ block.

Comments are used to comment out a line that you want to temporarily remove, or to add a comment above a section so that you know what is going on, or so that other people can see easily human readable advice on what is happening in the program.

Scope (Created by Squiggly Brackets Generally)

Scope is an important programming concept to be aware of. Basically, it’s that variables created in certain places only exist in those places.
Such as vegemite was (lets say) created in Australia, and available in Australia, but the US has no access to it.

You’ll learn more about this later, but in general, if you create a variable inside of squiggly brackets, it only exists inside of the squiggly brackets.

Conclusion

Now you have setup FlashDevelop, and have ran your first program, and traced out some text from it.

In the next section, we’ll start going into basic programming ideas that you need to know to be able to program in any language.

Other Articles in this Series

Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *