Create a Flash "Alphabet Soup" Wordsearch Game


This Cyber Monday Envato Tuts+ courses will be reduced to just $3. Don't miss out.

Today I'll show you how to create a simple wordsearch with a neat "highlighter" interface, which is easy to modify with your own words and layout. We'll be using Flash and AS3. Read on!

Final Result Preview

Let's take a look at the final result we will be working towards:

Step 1: Brief Overview

In this tutorial we'll use a series of ActionScript classes to create a classic Alphabet Soup wordsearch game. The objective of the game is to highlight letters to form a word. You will be able to create your own alphabet soup and include your own words.

Step 2: Flash Document Settings

Open Flash and create a 320x480px document. Set the Frame rate to 24fps.

Step 3: Interface

A simple orange interface will be used, featuring several shapes, buttons and MovieClips; continue to the next steps to build this GUI.

Step 4: Background

This background was created in Flash using simple rectangle shapes. The hex color for the orange is #EE923F.

Step 5: Title

To create the Title, first select the Text Tool (T), change the color to #EEEEEE, and write your title text. Then, duplicate the textfield (Cmd+ D), change the color to #C97B35, and send the new textfield backwards to create the letterpress effect.

Step 6: Buttons

Use again the Text Tool to create two buttons as shown in the image above. Convert them to buttons and give them descriptive instance names to easily use them later in the code. Convert the graphics in stage to a single MovieClip and name it TitleView - remember to check the Export for ActionScript box.

Step 7: Game Screen

This is the Game Screen - well, its background, as everything in this screen will be created dynamically using ActionScript 3.

Step 8: About Screen

The About screen will appear in front of the Title Screen; use the graphics and fonts used before to lay it out. Name it AboutView and remember to check the Export for ActionScript box.

Step 9: Alert

An alert will be shown when all the words are found, it will display a game over message and instructions. Use the Rectangle Tool to create it and set its instance name to AlertView, . Again mark the Export for ActionScript box.

Step 10: Sounds

We'll use sound effects to enhance the feeling of the game. You can find the sound used in this example in using the keyword bell.

Step 11: TweenNano

We'll use a different tween engine from the default included in flash, this will increase performace as well as it is easier to use.

You can download TweenNano from its official website.

Step 12: Set Document Class

We'll make our application interactive by using an external class. Add its name (Main) to the Class field in the Publish section of the Properties panel to associate the FLA with the Main document class.

Step 13: Create a New Class

Create a new (Cmd + N) ActionScript 3.0 Class and save it as in your class folder. This will be the document class.

Step 14: Class Structure

Create your basic class structure to begin writing your code.

Step 15: Required Classes

These are the classes we'll need to import for our class to work. The import directive makes externally defined classes and packages available to your code.

Step 16: Variables

These are the variables we'll use; read the comments in the code to know more about them. Some of their names are self explaining so there will be no comment there.

Step 17: Constructor

The constructor is a function that runs when an object is created from a class, this code is the first to execute when you make an instance of an object, or runs when the FLA is loaded if part of the Document Class.

It calls the necessary functions to start the game. Check those functions in the next steps.

Step 18: Add Title View

We start by adding the TitleView from the Library to the stage.

Step 19: Add Button Listeners

This will add the mouse listeners to the buttons in the title view, which will take us to the game or credits screen.

Step 20: Show Credits

The Credits screen is shown when the user clicks the credits button; a mouse listener is added to the full MovieClip to remove it.

Step 21: Hide Credits

When the Credits screen is clicked it will be tweened back and removed from the stage.

Step 22: Show Game View

The following lines remove the Title screen and leave the Game screen visible. It also calls the necessary functions to start the game - we'll add these functions in the next steps.

Let's stop here to do a quick test and make sure that our game code is working:

Keep in mind that some lines have been commented out as some functions haven't been created yet.

Remember that the Milestone files are included in the source download, so if for some reason your file doesn't mimic this one take a look at the source to see what can be causing that.

Step 23: Game Listeners

This function adds the mouse listeners required to draw the line that will highlight the letters.

Step 24: Build Soup

One of the most important functions in the game. It will create and position the characters to build the alphabet soup. We'll code its behavior over the next few steps.

Step 25: Create Character TextFields

Nested for-loops are used to read the multidimensional array; a TextField is created for every element found and a position is given to that textfield.

Step 26: Display Random Character

The words are already set in the original letters array, so the following code will change the 0s to random characters obtained from the Alphabet array. As this only changes the 0s the original characters will not be changed.

Step 27: Add Words List TextField

This TextField shows the words to find, it is placed at the bottom of the stage.

Step 28: List Words

In order to correctly display the words from the array we can cast it to a string, but we need to remove the commas that are added automatically.

This concludes the buildSoup() function.

Step 29: Start Selection Line

The selection line will start drawing when the user clicks on the stage; this function creates the shape and adds a listener to follow the mouse movement.

Step 30: Draw Selection Line

The next code draws the line in the direction of the mouse.

Let's stop here to do a quick test and make sure that our game code is working:

It draws the line, but doesn't stop. We'll deal with that in the next step.

Keep in mind that some lines have been commented as some functions haven't been created yet.

Remember that the Milestones are included in the source files, so if for some reason your file doesn't mimic this one take a look at the source to see what could be causing that.

Step 31: Detect Letters Function

When the mouse button is up, the draw method stops and the code to detect the highlighted words runs. I explain this code in the next steps.

Step 32: Get Selected Letters

To detect the highlighted characters we create a string variable that will store the TextFields that are hit by the selection line.

Step 33: Check Whether Word is on List

Next we compare the result to every word in the predefined array; if the word is found a sound is played, the correct variable gets incremented, and the word changes its color in the bottom bar.

Step 34: Check for Game Over

This code calls and alert when all the words are found.

Step 36: Alert

This function will stop the game and show the game over message, it also adds a mouse listener to reset the game when clicked.

This concludes the detectLetters() function.

Step 37: Restart Function

The next function will reload the SWF, resetting any variables and methods and returning to the first screen.

Step 38: Test Game

We are now ready to test our game and see if everything works as expected.

Step 39: Change Word List

You can change the word list by simply changing this line in the code:

This will only change the list of words that the code should detect; to make the words actually appear in the alphabet soup read the next step.

Step 40: Change Map Arrays

The Alphabet soup is created based on this 10x12 map array. Simply change the letters to the desired ones to add and position the words and use 0s for everything else. The quotes may make the process difficult so I recommend writting the characters only at first and then adding the quotes when the map is ready.


Create your own alphabet soups using the map array above.

I hope you liked this tutorial, thank you for reading!