I have this matching game and I want to show the players score on the next frame called “score1” in the movie. I’ve hit a dead end on this and any help would be great
package {
import flash.display.*;
import flash.events.*;
import flash.text.*;
import flash.utils.getTimer;
public class matching3 extends MovieClip {
// game constants
public static const boardWidth:uint = 6;
public static const boardHeight:uint = 6;
private static const cardHorizontalSpacing:Number = 52;
private static const cardVerticalSpacing:Number = 52;
private static const boardOffsetX:Number = 120;
private static const boardOffsetY:Number = 45;
private static const pointsForMatch:int = 100;
private static const pointsForMiss:int = -5;
private var firstCard:Card;
private var secondCard:Card;
private var cardsLeft:uint;
private var gameScore:int;
private var gameStartTime:uint;
private var gameTime:uint;
private var gameScoreField:TextField;
private var gameTimeField:TextField;
public function machting3():void {
// make a list of card numbers
var cardlist:Array = new Array();
for(var i:uint=0;i<boardWidth*boardHeight/2;i++) {
cardlist.push(i);
cardlist.push(i);
}
// create all the cards, position them, and assign a randomcard face to each
cardsLeft = 0;
for(var x:uint=0;x<boardWidth;x++) { // horizontal
for(var y:uint=0;y<boardHeight;y++) { // vertical
var c:Card = new Card(); // copy the movie clip
c.stop(); // stop on first frame
c.x = x*cardHorizontalSpacing+boardOffsetX; // set position
c.y = y*cardVerticalSpacing+boardOffsetY;
var r:uint = Math.floor(Math.random()*cardlist.length); // get a random face
c.cardface = cardlist[r]; // assign face to card
cardlist.splice(r,1); // remove face from list
c.addEventListener(MouseEvent.CLICK,clickCard); // have it listen for clicks
addChild(c); // show the card
cardsLeft++;
}
}
gameScoreField = new TextField();
addChild(gameScoreField);
gameScore = 0;
showGameScore();
gameTimeField = new TextField();
gameTimeField.x = 450;
addChild(gameTimeField);
gameStartTime = getTimer();
gameTime = 0;
addEventListener(Event.ENTER_FRAME,showTime);
}
// player clicked on a card
public function clickCard(event:MouseEvent) {
var thisCard:Card = (event.target as Card); // what card?
if (firstCard == null) { // first card in a pair
firstCard = thisCard; // note it
firstCard.gotoAndStop(thisCard.cardface+2); // turn it over
} else if (firstCard == thisCard) { // clicked first card again
firstCard.gotoAndStop(1); // turn back over
firstCard = null;
} else if (secondCard == null) { // second card in a pair
secondCard = thisCard; // note it
secondCard.gotoAndStop(thisCard.cardface+2); // turn it over
// compare two cards
if (firstCard.cardface == secondCard.cardface) {
// remove a match
removeChild(firstCard);
removeChild(secondCard);
// reset selection
firstCard = null;
secondCard = null;
// add points
gameScore += pointsForMatch;
showGameScore();
// check for game over
cardsLeft -= 2; // 2 less cards
if (cardsLeft == 0) {
MovieClip(root).gameScore = gameScore;
MovieClip(root).gameTime = clockTime(gameTime);
MovieClip(root).gotoAndStop("score1");
}
} else {
gameScore += pointsForMiss;
showGameScore();
}
} else { // starting to pick another pair
// reset previous pair
firstCard.gotoAndStop(1);
secondCard.gotoAndStop(1);
secondCard = null;
// select first card in next pair
firstCard = thisCard;
firstCard.gotoAndStop(thisCard.cardface+2);
}
}
public function showGameScore() {
gameScoreField.text = "Score: "+String(gameScore);
}
public function showTime(event:Event) {
gameTime = getTimer()-gameStartTime;
gameTimeField.text = "Time: "+clockTime(gameTime);
}
public function clockTime(ms:int) {
var seconds:int = Math.floor(ms/1000);
var minutes:int = Math.floor(seconds/60);
seconds -= minutes*60;
var timeString:String = minutes+":"+String(seconds+100).substr(1,2);
return timeString;
}
}
}