Skip to main content
April 16, 2013
Answered

How do I check game over using displayed MC frame numbers?

  • April 16, 2013
  • 2 replies
  • 785 views

Hi,

I'm relatively new to AS3.  I have a simple game in which I have 20 MCs placed directly on stage.  Each MC has 10 frames and each frame shows a unique object.  The only way I can check for "game over" is by checking which frame each MC is currently displaying.  Can anyone help please?

Thanks in advance

To clarify, each MC needs to be showing a particular frame (they don't have labels), so there is only one solution out of 200 possibilities.

Message was edited by: MurrayHeasman

This topic has been closed for replies.
Correct answer Ned Murphy

Hi Ned,

Thanks for your patience.  I'm pulling my hair out now.  This is the error message I'm getting every time I mouse_up:

ArgumentError: Error #1063: Argument count mismatch on TestGameOver_fla::MainTimeline/calculateProgress(). Expected 0, got 1.

Here's what I've done to date:

stop();

B18.addEventListener(MouseEvent.MOUSE_UP, calculateProgress);

B28.addEventListener(MouseEvent.MOUSE_UP, calculateProgress);

B38.addEventListener(MouseEvent.MOUSE_UP, calculateProgress);

var mcArray:Array = new Array();

mcArray = [B18, B28, B38];

var framesArray:Array = new Array();

framesArray = [2, 3, 4];

var gameOver = true;

function calculateProgress() {

          for (var i:uint=0; i<framesArray.length;i++) {

                    if (framesArray != mcArray.currentFrame) {

                              gameOver = false;

                              break;

                    }

          }

          if (gameOver) {

                    gotoAndStop(2);

          }

}

Message was edited by: MurrayHeasman


Keep your hair intact, otherwise some good stuff might leak out of what's beneath it.

The error is telling you exactly what the problem is.  You have a function named calculateProgress that is not written to accept an argument, but it needs to be since you have event listeners calling it, and event listeners pass an argument

function calculateProgress(e:MouseEvent) {

2 replies

Ned Murphy
Brainiac
April 16, 2013

Create one array that identifies the frame associated with each movieclip for the end of game status, and another array that has the movieclips' instance names in it in the same order.  Then anytime you need to check if the game is over, loop thru that array and check it against the currentFrame property of the movieclips.

The following could be part of whatever function you write to check....

var gameOver = true; // assume it is over

for(var:i:uint=0; i<framesArray.length;i++){

      if(framesArray != mcArray.currentFrame){

           gameOver = false;

           break;

      }

}

if(gameOver){

      //do whatever

}

April 17, 2013

Hi Ned,

Thanks for your suggestion.  I've tested this with just three mcs on stage and I'm almost there.  I had first used - framesArray = [2, 3, 4]; - because the first frame in each mc is blank, but when I advance each mc to the required frame nothing happened.  So I added some trace statements and they came out 1, 1, 1 - as they were the current frames when the movie loaded.  So I altered - framesArray = [1, 1, 1]; - and as expected the movie went straight to frame 2.

Thanks,

stop();

var mcArray:Array = new Array();

mcArray = [B18, B28, B38];

trace(B18.currentFrame);

trace(B28.currentFrame);

trace(B38.currentFrame);

var framesArray:Array = new Array();

framesArray = [1, 1, 1];

var gameOver = true;

for (var i:uint=0; i<framesArray.length;i++) {

          if (framesArray != mcArray.currentFrame) {

                    gameOver = false;

                    break;

                    }

          }

if (gameOver) {

          gotoAndStop(2);

}

Ned Murphy
Brainiac
April 17, 2013

As I said in my response, for the code I showed "The following could be part of whatever function you write to check...."

You need to place the code into a function that you execute anytime you think it is necessary to check if the game is over.  The way you have it written outside of any function it will only execute once when you enter that frame of the timeline.

Create a function and place that code inside of it.  When whatever happens that you would be driven to see if the game is over just call that function and it will see if the movieclips are in their necessary frames.

April 16, 2013

Sorry, long day and very tired now.  Number of possibilities is far more that 200, duh!