Hangman
Up

How to make a dynamic hangman game in Flash 8 with XML and ActionScript

This is a simplified version of a tutorial on the excellent site www.flashexplained.com

In this detailed lesson made for Flash 8 and ActionScript 2.0, I will show you how to create a completely dynamic hangman game. This lesson is intended for intermediate or advanced users of ActionScript. Before continuing with this lesson, you should already know some fundamental ActionScript concepts, such as variables, if/else conditional logic, for loops, function basics, paths, dynamic text fields and movie clip events.

Here is the finished SWF animation:

 

It looks quite nice, simple and easy to use, doesn't it? The reason it's so nice and easy to use is that we're going to work quite hard to make it be that way...

You might be surprised how many layers are used in this simple-looking project - this is not intended to make the project more difficult but rather to make the project easier - the point is that you can lock layers that you are not working on so that they don't get modified accidentally. In a similar way, this project makes use of movie clip symbols. The Flash animation itself is a movie so the use of movie clip symbols inside our animation implies that we have 'movies within our movie'. This allows us to keep the main timeline as simple as possible and to use a modular approach, opening up the movie clip symbols for editing only when necessary and otherwise leaving them closed so that our work area is not cluttered.

What you will learn in this tutorial

In this tutorial, I will show you:

bulletHow to create, read data from and manipulate a String object,
bulletHow to compare two different String objects,
bulletHow to create a function that will pick a random word that has to be guessed,
bulletHow to dynamically pull out a movie clip from the Library several times and display a different letter in each movie clip instance (this will create the letter buttons) and much more along the way.

In the first optional extension to this project I will show you:

bulletWhat is an XML file,
bulletHow to create an XML file where all the game data (words) will be stored (it's great to have the data in a separate file since this means we can modify the data without having to modify the FLA file or even use Flash at all),
bulletHow to create and use an XML object in ActionScript to retrieve data from the XML file,
bulletHow to parse (process) the XML data and place it into an Array object,

In the second optional extension to this project I will show you:

bulletHow to create a simple text file from which a single value will be loaded,
bulletHow to create and use a LoadVars object to load the data from the text file.

So, roll up your sleeves and follow my guidance. Let’s go!

Click HERE or the link below to jump to the first part of this 5 page tutorial (the last two pages are optional).

Previous Up Next