This is a simple finding game where you find all of the items hidden in the image. In this program, you'll also divide the program into scenes for further modularity. (See the help on Using Scenes for more information.) Scene 1 will contain just 1 keyframe with instructions and a start button that goes to the second scene, frame 1. In this example, the second scene is named "Play" and the first frame of "Play" is also named "Play" so the code on the button in Scene 1, frame 1 is:
on (release) {gotoAndPlay ("Play", "Play");
}
Then, this program uses another scene named "Game Over" that has a restart button and a win message. This scene has only 1 keyframe and on it is a button with the restart code, which is:
on (release) {gotoAndPlay ("Play", 1);
}
The "Play" scene has the majority of the scripting, but it's still relatively simple. The "Play" scene is also one 1 frame long, but multiple layers make the finding game more complex. One layer should be for the hidden objects, which are cats in this example. The other layer(s) should be used for background and foreground cover to help conceal the hidden objects.
In this example, the cats are movie clips that are placed on the "Play" scene and each cat instance is numbered "cat0", "cat1"... through "cat6". The code below changes the color of the cat when clicked and counts how many cats have been found in order to figure out when all cats have been found and when the game is over.
The code below should actually be placed on a movie clip on the "Play" scene that's off of the stage. By placing the code on a completely separate movie clip, it's easier to keep track of the code and to prevent confusion.
onClipEvent (load) {
// create array to keep track of
// which ones found
found = [];
for (i=0; i<7; i++) {
found[i] = false;
}
}
onClipEvent (mouseDown) {
// record location of click
x = _root._xmouse;
y = _root._ymouse;
// loop through all cats to see if any hit
for (i=0; i<7; i++) {
if (_root["cat"+i].hitTest(x, y, false)) {
// change color of cat
myColor = new Color(_root["cat"+i]);
myColor.setTransform({rb:128, bb:0, gb:0});
// record that this one was found
found[i] = true;
break;
}
}
// see if all cats found
gameover = true;
for (i=0; i<7; i++) {
if (found[i] == false) {
// this cat not found, game not over
gameover = false;
}
}
// go to end frame if all cats found
if (gameover) {
_root.gotoAndPlay("Game Over");
}
}
Here's the finding cats game and here's the .fla file.