Create a "Frenzic" Inspired Puzzle Game in Flash


Take a look at this Premium Tutorial to create an entertaining puzzle game, inspired by Frenzic, using Flash and ActionScript 3.

In the demo above, fill the outer boxes with colored squares. You get more points for filling a box with squares that are all the same color.

Step 1: Brief Overview

Using the Flash drawing tools we'll create a good looking graphic interface that will be powered by several ActionScript 3 classes.

The player will be able to click on four different locations to sort the color blocks on the squares, more points are earned if you fill a square with a single block color.

Step 2: Flash Document Settings

Open Flash and create a 320 pixels wide, 480 pixels tall document. Set the Frame rate to 24fps.

Step 3: Interface

A colorful nice looking interface will be displayed, this involves multiple shapes, buttons, sounds and more.

Continue to the next steps to learn how to create this GUI.

Step 4: Background

Select the Rectangle Tool (R) to create a 320x480px #0D6191, #001217 rectangle and center it in the stage. Use the same tool to crate a 2x480px black line with 20% alpha, press CMD+D to duplicate it multiple times, and spread the lines out to get the effect in the image above.

Step 5: Title View

Select the Text Tool (T), select a good looking font and write your game title. I used this format: Orbitron Bold, 60pt, #A3FF24. You can add a simple glow filter to make it look better.

Use the same technique to create two buttons, align them to the center and name them startB and creditsB. Convert all to a Movie Clip and set its name to TitleView; mark the Export for ActionScript box and delete the clip from the stage.

Step 6: Score and Lives

This will be the GameView. Add the background MC to the stage and create two Dynamic Text Fields and place them as shown in the image. Name the Text Fields livesTF and scoreTF.

Step 7: Containers

Use the Rectangle Tool (R) to create a 70x70px square and fill it using the background gradient, convert it to MC and press CMD+D to duplicate it so that you have five in total. Use the Align Panel to place them as shown in the image.

The instance names should match their positions -- that is: up, down, left, right and the center will be mainHolder.

Step 8: Blocks

Use the same technique used in the last step to create three 30x30px blocks, convert them to MC and name them according to its color: OrangeBlock, PurpleBlock and GreenBlock. Don't forget to mark the Export for ActionScript box.

Step 9: Alert

An alert will be shown when you lose all your lives, and it will show the final score you reached. Use the Rectangle Primitive Tool to create it and fill it with this Linear gradient: #000000 to #333333. Set its instance name to AlertView and mark the Export for ActionScript box.

Step 10: Credits

This screen will be easy to make as we already have all the graphics. Set its instance name to CreditsView and mark the Export for ActionScript box.

Step 11: Tween Nano

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 Tween Nano from its official website.

Step 12: Soungle

We'll use Sound Effects to enhance the feeling of the game, you can find the sounds used in this example in using the keywords bell and buzz. Add them to your Library, with class names of Bell, Bell4, and Buzz, respectively.

Step 13: Create a new ActionScript Class

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

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-explanatory 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 (when in the Document Class) the first to run when the project loads.

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

Step 18: Add Title View

We'll start by adding the TitleView to the stage; if we don't do this the first screen shown will be the GameView.

Step 19: Add Vectors Values

The blockColor vector is used to create a new instance of the selected block; the parameters are the blocks that we created in the previous steps.

The positions vector stores the possible x and y positions that a block can have; mixing this will give us the final position relative to the mainHolder MC.

Step 20: Button Listeners

In this function we add the mouse listeners to the buttons in the title view. These will take us to the game screen or the credits screen.

Step 21: Show Credits

The credits screen is shown when the user clicks the credits button, a mouse listener is added to the full MC to remove it.

Step 22: Hide Credits

When the credits screen is clicked, it'll be tweened out of the stage and removed.

Step 23: Game View

When the Start button is pressed, the title view is tweened and removed revealing the game view.

Let's stop here to make a quick test and make sure that our screen switcher code is working (test Credits first so you can go back). Set the document class of your FLA to Main.

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 can be causing that.

Step 24: Game Listeners

Get back to the code and add the following function. It will add a Mouse Listener to the squares so you can click them to place the current block.

Step 25: Container Arrays

These arrays are created inside the square MovieClips, they are used to register the blocks, colors, and positions inside every square.

The letters represent the following positions:

  • a: top-left
  • b: top-right
  • c: bottom-left
  • d: bottom-right

Continue the addListeners() function:

Step 26: Generate Random Block Color

This code picks a random block color from the Vector, this will be used to instantiate the actual block. A parameter is used to determine whether the Timer to start counting will be activated.

Step 27: Add New Block

After selecting the block color, the position where it will be placed is calculated using the positions Vector and then added to the blocks vector and the stage. Continue the newBlock() function:

Step 28: Check For an Available Space

Before continuing with the game, we must check that the newly created block can actually be placed in a square container. The following code checks every container array to make sure that there is an empty position available in one of the boxes where the block can be placed; if there isn't, the block is destroyed and the function is called again to generate another one.

If you used a different layout for your game, make sure you change the value that you're checking (i.e. not '35,35', as your game's blocks won't necessarily appear at that point).

Step 29: Start Timer

The timer starts counting when the function is called for the first time.

Step 30: Lives

Three seconds are given to place a block in a square container, if that time passes and the block is still in the center square, a life will be removed.

Step 31: Unused Blocks

After removing the life, the block in the center square will be destroyed and a new block will be generated. This code also checks if the player is out of lives and calls a function that we'll write later.

Let's take another pause to see how our code works at this point:

Step 32: Place Blocks

This function runs when the player clicks any of the container squares. It basically checks whether the correct position is available to place the square and places it if true. The function in the next step is called when the block is placed.

Again, you might need to change the values that are checked here, to match the position of your blocks.

Step 33: Add Block to Array

When the block is placed in the container, we add the block to the array that keeps record of the stored blocks in that container. This will help us determine when the container is full.

Step 34: Score

Every block placed increments the score by one. When the box is full the score will increase by 50 and if the box is completely filled by a single color the total score will increase by 200.

Step 35: Sound

A short sound will indicate that the block was placed.

Step 36: Complete Single Color Container

The next code checks whether the container was filled by a single color block using the container array. It increments the score by 200, plays the corresponding sound and bounces the container as a visual sign. It also clears the variables in the container.

Step 37: Complete Container

This code runs when the container is full but the blocks inside aren't the same color.

Step 38: Restart Timer

After clearing the full containers the score is set to the Text Field on the stage, the timer is reset, and another block is called.

Step 39: Alert

The alert function runs when the player is out of lives; it displays the final score reached and adds a listener to go back to the title screen.

Step 40: Restart

The next function will reload the swf, restarting any variable, method and returning to the Title Screen.


You've crated a very entertaining game, try to add your own features and graphics.

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