--------------------------------------------------------------------------------------------------------------------
0- SET STAGE SIZE 800X600
1- MAKE THREE LAYERS WITH 50 FRAMES
2- GIVE LAYER NAMES CONTENTS , LABELS, ACTION
3- ON CONTENTS LAYER FRAME 1 NEED TWO BUTTON WITH INSTANCE NAME
btnStartGame , btnHowToPlay
READ MORE:
DOWNLOAD SOURCE FILE:
-----------------------------------------------------------------------------------------------------------------------
ON CONTENTS LAYER FRAME 1 NEED TWO BUTTON IMAGES
btnStartGame X=563.70 , Y = 336.05 , W =213.65 , H = 48.70
btnHowToPlay X=563.70 , Y = 392.10 , W =232.45 , H = 48.70
---------------------------------------------------------------------------------------------------------------
ON CONTENTS LAYER FRAME 10 NEED ONE BITMAP IMAGE
X=49.55 , Y = 30.00 , W = 726.95 , H = 549.85
ON CONTENTS LAYER FRAME 10 NEED ONE BUTTON WITH INSTANCE NAME
btnBack X=730.25 , Y = 556.15 , W =92.55 , H = 48.70
ON CONTENTS LAYER FRAME 20 NEED ONE BITMAP IMAGE YOU WON
ON CENTER OF SCREEN
ON CONTENTS LAYER FRAME 30 NEED ONE BITMAP IMAGE YOU LOST
ON CENTER OF SCREEN
ON CONTENTS LAYER FRAME 40 NEED TWO TEXT BOX WITH INSTANCE NAME
DOUBLE CLICK CARD MOVIE CLIP AND MAKE 80 FRAMES WITH STOP ACTION
AND TWO LAYERS ONE FOR LABELS LAYER AND CONTENTS
LABELS NAME FRAME 2 back , FRAME 10 Card 1 AND SO ON...........
back , Card 1 Card MOVIE CLIP SEE TIME LINE INDEX
---------------------------------------------------------------------------------------------------------------------
FRONT MAIN LABEL LAYER CODE
startMenu(); startHowToPlay(); startWin(); startLose();
startGame();
---------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------
COPY AND PASTE BELOW CODE
----------------------------------------------------------------------------------------------------------------------
import flash.display.*;
import flash.events.*;
import flash.ui.*;
var score, life:Number;
var doLoseLife, gotoWin, gotoLose:Boolean;
var firstCard, secondCard:Card;
var cardValues, cards:Array;
function Memory(){
}
function startMenu(){
stop();
btnStartGame.addEventListener(MouseEvent.CLICK, gotoStartGame);
btnHowToPlay.addEventListener(MouseEvent.CLICK, gotoHowToPlay);
}
function startHowToPlay(){
btnBack.addEventListener(MouseEvent.CLICK, gotoMenu);
}
function startWin(){
btnBack.addEventListener(MouseEvent.CLICK, gotoMenu);
}
function startLose(){
btnBack.addEventListener(MouseEvent.CLICK, gotoMenu);
}
function startGame(){
score = 0;
life = 10;
doLoseLife = false;
gotoWin = false;
gotoLose = false;
firstCard = null;
secondCard = null;
cards = new Array();
setupGame();
cardValues = new Array("card1","card1","card2","card2","card3","card3","card4","card4",
"card5","card5","card6","card6","card7","card7");
for (var i=0; i<100; i++){
var swap1 = Math.floor(Math.random()*14);
var swap2 = Math.floor(Math.random()*14);
var tempValue = cardValues[swap1];
cardValues[swap1] = cardValues[swap2];
cardValues[swap2] = tempValue;
}
for (var i=0; i<14; i++){
cards[i].hiddenValue = cardValues[i];
cards[i].addEventListener(MouseEvent.CLICK, flipCard);
}
addEventListener(Event.ENTER_FRAME,update);
stage.focus = this;
}
function setupGame(){
for (var i=0; i< MovieClip(root).numChildren; i++){
var object = MovieClip(root).getChildAt(i);
if (object is Card){
cards.push(object)
}}}
function gotoStartGame(evt:MouseEvent){
btnStartGame.removeEventListener(MouseEvent.CLICK, gotoStartGame);
btnHowToPlay.removeEventListener(MouseEvent.CLICK, gotoHowToPlay);
gotoAndStop("game");
}
function gotoHowToPlay(evt:MouseEvent){
btnStartGame.removeEventListener(MouseEvent.CLICK, gotoStartGame);
btnHowToPlay.removeEventListener(MouseEvent.CLICK, gotoHowToPlay);
gotoAndStop("howtoplay");
}
function gotoMenu(evt:MouseEvent){
btnBack.removeEventListener(MouseEvent.CLICK, gotoMenu);
gotoAndStop("menu");
}
function flipCard(evt:MouseEvent){
if (firstCard == null){
firstCard = evt.currentTarget as Card;
firstCard.gotoAndStop(firstCard.hiddenValue);
}
else if (secondCard == null){
if (firstCard == evt.currentTarget as Card)
return;
secondCard = evt.currentTarget as Card;
secondCard.gotoAndStop(secondCard.hiddenValue);
doLoseLife = true;
}
else{
firstCard.gotoAndStop("back");
secondCard.gotoAndStop("back");
secondCard = null;
firstCard = evt.currentTarget as Card;
firstCard.gotoAndStop(firstCard.hiddenValue);
}}
function update(evt:Event){
handleUserInput();
handleGameLogic();
handleDraw();
if (gotoWin)
triggerGoToWin();
else if (gotoLose)
triggerGoToLose();
}
function handleUserInput(){
}
function handleGameLogic(){
if (firstCard != null && secondCard != null){
if (firstCard.hiddenValue == secondCard.hiddenValue){
removeChild(firstCard);
removeChild(secondCard);
score += 10;
firstCard = null;
secondCard = null;
}
else if (doLoseLife){
doLoseLife = false;
}}
if (score >= 70){
gotoWin = true;
}
if (life <= 0){
gotoLose = true;
}}
function handleDraw(){
txtScoreP1.text = String(score);
txtLife.text = String(life);
}
function triggerGoToWin(){
removeEventListener(Event.ENTER_FRAME, update);
gotoAndStop("win");
}
function triggerGoToLose(){
removeEventListener(Event.ENTER_FRAME, update);
gotoAndStop("lose");
}
function resetGame(){
for (var i in cards)
cards[i].gotoAndStop("back");
}
----------------------------------------------------------------------------------------------------------------------
YOU CAN USE UPPER CODE IN CLASS FILE Memory.as
YOUR FLA AND CLASS FILE SAVE IN SAME FOLDER
----------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
COPY AND PASTE BELOW CODE AND SAVE AS Memory.as
--------------------------------------------------------------------------------------------------------------
package {
import flash.display.*;
import flash.events.*;
import flash.ui.*;
public class Memory extends MovieClip{
private var score, life:Number;
private var doLoseLife, gotoWin, gotoLose:Boolean;
private var firstCard, secondCard:Card;
private var cardValues, cards:Array;
public function Memory(){
}
public function startMenu(){
stop();
btnStartGame.addEventListener(MouseEvent.CLICK, gotoStartGame);
btnHowToPlay.addEventListener(MouseEvent.CLICK, gotoHowToPlay);
}
public function startHowToPlay(){
btnBack.addEventListener(MouseEvent.CLICK, gotoMenu);
}
public function startWin(){
btnBack.addEventListener(MouseEvent.CLICK, gotoMenu);
}
public function startLose(){
btnBack.addEventListener(MouseEvent.CLICK, gotoMenu);
}
public function startGame(){
score = 0;
life = 10;
doLoseLife = false;
gotoWin = false;
gotoLose = false;
firstCard = null;
secondCard = null;
cards = new Array();
setupGame();
cardValues = new Array("card1","card1","card2","card2","card3","card3","card4","card4",
"card5","card5","card6","card6","card7","card7");
for (var i=0; i<100; i++){
var swap1 = Math.floor(Math.random()*14);
var swap2 = Math.floor(Math.random()*14);
var tempValue = cardValues[swap1];
cardValues[swap1] = cardValues[swap2];
cardValues[swap2] = tempValue;
}
for (var i=0; i<14; i++){
cards[i].hiddenValue = cardValues[i];
cards[i].addEventListener(MouseEvent.CLICK, flipCard);
}
addEventListener(Event.ENTER_FRAME,update);
stage.focus = this;
}
private function setupGame(){
for (var i=0; i< MovieClip(root).numChildren; i++){
var object = MovieClip(root).getChildAt(i);
if (object is Card){
cards.push(object)
}}}
private function gotoStartGame(evt:MouseEvent){
btnStartGame.removeEventListener(MouseEvent.CLICK, gotoStartGame);
btnHowToPlay.removeEventListener(MouseEvent.CLICK, gotoHowToPlay);
gotoAndStop("game");
}
private function gotoHowToPlay(evt:MouseEvent){
btnStartGame.removeEventListener(MouseEvent.CLICK, gotoStartGame);
btnHowToPlay.removeEventListener(MouseEvent.CLICK, gotoHowToPlay);
gotoAndStop("howtoplay");
}
private function gotoMenu(evt:MouseEvent){
btnBack.removeEventListener(MouseEvent.CLICK, gotoMenu);
gotoAndStop("menu");
}
private function flipCard(evt:MouseEvent){
if (firstCard == null){
firstCard = evt.currentTarget as Card;
firstCard.gotoAndStop(firstCard.hiddenValue);
}
else if (secondCard == null){
if (firstCard == evt.currentTarget as Card)
return;
secondCard = evt.currentTarget as Card;
secondCard.gotoAndStop(secondCard.hiddenValue);
doLoseLife = true;
}
else{
firstCard.gotoAndStop("back");
secondCard.gotoAndStop("back");
secondCard = null;
firstCard = evt.currentTarget as Card;
firstCard.gotoAndStop(firstCard.hiddenValue);
}}
public function update(evt:Event){
handleUserInput();
handleGameLogic();
handleDraw();
if (gotoWin)
triggerGoToWin();
else if (gotoLose)
triggerGoToLose();
}
private function handleUserInput(){
}
private function handleGameLogic(){
if (firstCard != null && secondCard != null){
if (firstCard.hiddenValue == secondCard.hiddenValue){
removeChild(firstCard);
removeChild(secondCard);
score += 10;
firstCard = null;
secondCard = null;
}
else if (doLoseLife){
doLoseLife = false;
}}
if (score >= 70){
gotoWin = true;
}
if (life <= 0){
gotoLose = true;
}}
private function handleDraw(){
txtScoreP1.text = String(score);
txtLife.text = String(life);
}
private function triggerGoToWin(){
removeEventListener(Event.ENTER_FRAME, update);
gotoAndStop("win");
}
private function triggerGoToLose(){
removeEventListener(Event.ENTER_FRAME, update);
gotoAndStop("lose");
}
private function resetGame(){
for (var i in cards)
cards[i].gotoAndStop("back");
}}}
HOW CHANGE CLASS FILE INTO SIMPLE ACTION SCRIPT
1- I USE NOTE PAD++ AND DELETE PACKAGE LINE package { AND REMOVE
END CURLY BRACKET } I DELETE public class Memory extends MovieClip{
{ AND REMOVE END CURLY BRACKET } AT THE END OF CODE FOR EQUAL CURLY
BRACKET NUMBER
2- I REPLACE private AND public WORDS WITH EMPTY BOX IN NOTE PAD++
----------------------------------------------------------------------------------------------------------------
EmoticonEmoticon