Flash Game Development with Flex and Actionscript - Getting Started

Article by Matthew Casperson (4,911 pts )
Edited & published by David Berry (2,943 pts ) on Dec 15, 2009

Get started with Flash game development. This article shows you which tools to download and details the first steps in creating a Flash game using Flex and Actionscript.

Getting Started

With Flash Player and the Flex SDK Adobe has supplied everything you need to start creating your own Flash games. Creating a Flash game using Flex has several advantages like:

  • Cross platform compatibility – there is a flash player for every major platform
  • Easy deployment – publishing the game is as simple as uploading the swf file
  • (Almost) zero installation requirements – an end user only needs a web browser with the Flash player plugin installed
  • Free tools - all you need is the free Flex SDK and a text editor

This article series will step you through the process of creating a 2D Flash game using Flex, with the result being a complete game in the style of the old school top down shooters.

To get started you will first need to download the Flex 3 SDK from http://www.adobe.com/products/flex/flexdownloads/. The SDK contains all the tools you will need to compile the source code presented here into a SWF file that can be added to a web page. You will also need a decent text editor. I quite like Textpad, which can be downloaded from http://www.textpad.com/. Finally you will need to download a Flash debug player from http://www.adobe.com/support/flashplayer/downloads.html. The debug player will allow you to open up a SWF file directly without having to create a web page to contain it. With these three tools you are ready to start coding.

The graphics used in the game are courtsey of spritelib, which you can download from http://www.flyingyogi.com/fun/spritelib.html.

Creating the Application

Conceptually Flex splits up an average program into two sections: the GUI and the Actionscript code. The GUI is created in an MXML file, which is an XML file that contains user interface elements nested in tags very similar to HTML. Note that the MXML file can contain Actionscript code inside an mx:Script tag, but the main focus of the MXML file is to define the user interface.

The top level tag of an MXML file is the mx:Application tag. This Application object is the entry point of the Flex application, and is the most logical place to start.

main.mxml Actionscript Source Code

<?xml version="1.0" encoding="utf-8"?>

<mx:Application

xmlns:mx="http://www.adobe.com/2006/mxml"

layout="absolute"

width="600"

height="400"

frameRate="100"

creationComplete="CreationComplete()"

enterFrame="EnterFrame(event)">

<mx:Script><![CDATA[

public function CreationComplete():void

{

}

public function EnterFrame(event:Event):void

{

}

]]></mx:Script>

</mx:Application>

We start by defining some of the properties of the Application object. These properties can be set through attributes in the mx:Application tag. This should look familiar to anyone who has written HTML.

width and height

Specify the screen size of the program in pixels.

framerate

Specifies a limit on the frames per second. The default is 24, but since we want the game to run as fast as possible it’s best to override this with a much higher number. Note that just setting the framerate to 100 doesn’t guarantee that the frame rate will always be 100 (or even get anywhere near it). This property just sets a ceiling on what the frame rate could be.

creationComplete

Attaches a function to be called when the Application has been created. We use this as the entry point in the program.

enterFrame

Attaches a function to be called every time the screen is redrawn. We will use this to repaint the screen with the next frame of the game.

The mx:Script tag gives us a place to write some Actionscript code. The [CDATA[ ]] tag just means that any special characters inside the mx:Script tag will be interpreted as text rather than XML characters. Inside the mx:Script tag we need to add the two functions which match the values for the creationComplete and enterFrame properties.

Compiling and Running

To compile the program you need to run the command mxmlc main.mxml from the command prompt. You can then open up the resulting main.swf file in the Flash debug player through File->Open.

And the end result? A blank screen that does nothing. Not terribly exciting I’ll admit, but it is a start. We will build off this code in part 2 of the series to start drawing to the screen.

Go back to Flash Game Development with Flex and ActionScript

Related Files

Images

CompilingThe Flash game

Related Article

Flixel LogoCreating a platform game with Flixel and Adobe Flex

This tutorial series shows you how to use the Flixel ActionScript game engine to create a simple platform game.

27 Comments

Showing page 1 of 3 (27 Comments)
Dec 9, 2009 4:29 AM
madhuka
Great work!!
I was searching such one it gr8!!
keep it Up!!

Super Work Mathew
Dec 1, 2009 5:20 PM
RE: Flash Game Development with Flex and Actionscript - Getting Started
I don't actually have much experience with Flash itself, but from what I can gather its strength lies in its animation and creating fancy user interfaces. So I guess it depends on what sort of game you were making. If it was a point and click game, Flash would probably be the better choice. If it is something more involved, then most of the logic will be implemented in ActionScript anyway, which means Flash or Flex would do.

I prefer Flex simply because the development flow is more familiar to other development platforms that I had experience with.
Dec 1, 2009 12:08 PM
AlexC
Great article!
Thank you for the great article. I'm tasked with building about 5 different games for kids 6 - 10, showing them how to eat healthier. I have Flex experience building RIA but never games.

Some folks say Flash is better for building games but my Flash experience is very basic. You think my task is doable in Flex alone? Thanks.
Nov 24, 2009 1:02 PM
Mat
i have great ideas
hey i have great ideas , my only failing is im somewhat of a dreamer , and i have very ittle programming skills , so i want to link up with someone who could make my games , i wouldnt even care about credit , i just want to have some good game to play :P
Nov 24, 2009 10:39 AM
Mark Gale
Monetizing
very good article! i'd like to add that monetizing is an important part of game development... i've tried at www.gameknob.com and have good earnings at my game
Nov 20, 2009 7:49 AM
Nikos
RTS game in flex 4
I'm developing a RTS game in flex 4. I'm using the new spark components to base my game objects on. I was wondering if your code(before I sit down and work through theis tut) will help me with the RTS collision detection system I'm having a hard time coding, or could you point me to other resources?

thanks
Nov 4, 2009 5:20 AM
Pranab
Flash Action Scriipt
I want to develop games using flash action script
Nov 3, 2009 3:21 PM
le thanh tam
how to create webgame by using flex 3 and as3
I have just leant to deveplop webgame.I don't know where to start.Can you help me?
Oct 26, 2009 5:15 PM
RE: Flash Game Development with Flex and Actionscript - Getting Started
Use the Wii remote in Flash:
http://wiiflash.bytearray.org/

As for other controllers, I'm not sure. I have never done it myself.
Oct 26, 2009 2:51 PM
OmegaWarrior
Controller input?
Do you know if there is any way to get a flex/flash application to accept input from a game controller?
Showing page 1 of 3 (27 Comments)
 
Subscribe to Web Development
RSS
Get free weekly updates, directly to your inbox.
Subscribe
Browse Web Development