Tutorial for a Flash Memory Game

Written by sue smith Google
  • Share
  • Tweet
  • Share
  • Pin
  • Email
Tutorial for a Flash Memory Game
Creating a memory game in Flash requires only small amounts of code. (cards image by Aleksandr Lobanov from Fotolia.com)

Memory games are straightforward to create in Flash. Flash movie interactivity can be achieved without developers having to write huge amounts of code. You will have to use some ActionScript, but the logic of a memory game is simple and therefore not too difficult to create. The main activities involved in creating a Flash memory game will most likely be: creating the visual elements (designing the interface and objects), implementing the game functionality using ActionScript, and testing the game to ensure it functions correctly.

Skill level:
Moderate

Other People Are Reading

Instructions

  1. 1

    Create a new Flash file and add the basic visual elements. Decide on the size and layout you want to use for your game and create background images. Work out a rough design before you actually start building the elements in Flash. Sketch a design on paper.

  2. 2

    Create your memory cards. Each card should be the same size and shape, so you may want to use a generic background image for them by creating a Graphic Symbol and including this in each card Symbol. Make your cards Movie Clip Symbols and give them appropriate Symbol and Instance Names. Make sure there are pairs of matching cards in the game. Edit your card Movie Clips so that they have two frames. Create Keyframes within each card Movie Clip and name them something like "front" and "back," in which the face and rear sides of the card are shown respectively.

  3. 3

    Within each card Movie Clip, include a variable in ActionScript. You can do this by adding a new layer and inserting code such as this:

    var my Reference:Number=1;

    Within matching cards (i.e. the pairs within your game) include the same reference number. For example, if you have animals on your memory cards, within the two cards that have cats on them, you should include the same reference number. This reference will be used to determine whether a pair of cards matches or not.

  4. 4

    Add code determining what happens when a card is clicked, bringing your game logic into play. Your memory cards should all begin the game face down. When the user clicks on one, it should turn over. To implement this effect, you can add ActionScript code instructing the relevant card Movie Clip to "gotoAndStop" at the "front" frame. When the user clicks another card, you will need to test whether it matches the first one. Check whether the reference numbers in the two chosen cards are the same using the following conditional test:

    if(firstCard.myReference==secondCard.myReference){

    //code goes here

    }

    If the numbers do not match, the cards should be instructed to turn back over, which requires them to go to the "back" frame. If the numbers do match, the cards can remain facing up. Either way, the player should then be able to make a new selection.

  5. 5

    Define what happens at the different stages in your game. Each time the player chooses a card, your game logic will need to behave differently depending on whether the card is the first or second in a pair. For example, when the card is the first in a pair, you simply turn it over and wait for the second one to be selected. When it is the second in a pair, you need to carry out the test to see if the cards match. To do this, you can include a Boolean variable that simply alternates each time a card is clicked. At the top of your ActionScript code:

    var second:Boolean=false;

    var firstCard_mc:MovieClip;

    var secondCard_mc:MovieClip;

    Within the "onPress" code for each card Movie Clip:

    if(second)

    {

    secondCard_mc=this;

    if(firstCard_mc.myReference==secondCard_mc.myReference) { trace("CORRECT"); }

    else { firstCard_mc.gotoAndStop("back"); secondCard_mc.gotoAndStop("back"); }

    second=false;

    }

    else

    {

    firstCard_mc=this;

    second=true;

    }

    This is a simplistic example and so you may wish to create more sophisticated effects once you have the game logic in place.

Tips and warnings

  • Remember to add code to determine what happens when the user has correctly paired all of the cards within the game. You can optionally include score keeping.
  • The logic for a memory game is deceptively simple. Don't worry if you don't get it right first time; simply make changes and try again.

Don't Miss

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.