Question

so I have been working on a game called rock scissors paper lizard spock.

I got this error: ArgumentError: Error #1063: Argument count mismatch on FlashGame_fla::MainTimeline/backtoBanana(). Expected 0, got 1.

this is my main code:

import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.text.TextFormat;

rulesButton.addEventListener(MouseEvent.CLICK, toggleRule);
gameRules.addEventListener(MouseEvent.CLICK, toggleRule);
gameRules.visible = false;
gameRules.buttonMode = true;

function toggleRule(evt:MouseEvent):void 
{
    gameRules.visible = ! gameRules.visible;
}

menuButton.addEventListener(MouseEvent.CLICK, Click_backtoMain);

function Click_backtoMain(event:MouseEvent):void
{
    gotoAndStop(213);
}

var isRolling:Boolean = false; //defalt is "false"
var pDieVal:int = 0;
var gDieVal:int = 0;    
var pScore:int = 0;
var gScore:int = 0;
var pRolls:int = 0;

pDieMC.stop();
gDieMC.stop();
msgDisplay.text = "Click on the banana \nbutton to roll the die!";
pScoreDisplay.text = "0";
gScoreDisplay.text = "0";

rollButton.addEventListener(MouseEvent.CLICK, rollDie);
rollButton.addEventListener(MouseEvent.CLICK, dieRoll);

bananaWinLose.visible = false;
gameOverBananaMC.visible = false;
toMenuBtn.visible = false;
rollAgainBtn.visible = false;

function rollDie(evt:MouseEvent): void
{
    if (isRolling) 
    {
        //change flag to show die is NOT rolling
        isRolling = false;
        //change the label on the button to "BANANA!"
        buttonDisplay.text = "BANANA!";
        // STOP the dice animations
        pDieVal= Math.ceil(Math.random() * pDieMC.totalFrames);
        pDieMC.gotoAndStop(pDieVal);
        gDieVal = Math.ceil(Math.random() * gDieMC.totalFrames);
        gDieMC.gotoAndStop(gDieVal);
        //set message display to an empty string
        msgDisplay.text = "";
        whoWon();
        score();
    } 
    else 
    {
        //change flag to show die is rolling
        isRolling = true;
        //change the label on the button to "Stop"
        buttonDisplay.text = "POPADAM!";
        //PLAY the dice animations
        pDieMC.play();
        gDieMC.play();
        //clear the message display
        msgDisplay.text = "";
    }
}

function whoWon():void 
{
    // is it a tie?
    if (pDieVal == gDieVal) 
    {
        msgDisplay.text = "Papoi?! It's a tie!";
    } 
    else 
    {
        // assume the player has lost
        var hasPlayerWon:Boolean = false;
        // determine if the player wins
        if (pDieVal == 1 && (gDieVal == 4 || gDieVal == 5)) 
        {
            hasPlayerWon = true;
        } 
        else if (pDieVal == 2 && (gDieVal == 1 || gDieVal == 5)) 
        {
            hasPlayerWon = true;
        } 
        else if (pDieVal == 3 && (gDieVal == 1 || gDieVal == 2)) 
        {
            hasPlayerWon = true;
        } 
        else if (pDieVal == 4 && (gDieVal == 3 || gDieVal == 2)) 
        {
            hasPlayerWon = true;
        } 
        else if (pDieVal == 5 && (gDieVal == 3 || gDieVal == 4)) 
        {
            hasPlayerWon = true;
        }
        // display the results to the player
        if (hasPlayerWon) 
        {
            msgDisplay.text = "Yay! You win!";
        } 
        else 
        {
            msgDisplay.text = "Boo! Stuart wins!";
        }
    }
}

function dieRoll(evt:MouseEvent):void 
{
    trace("calculating pRolls");
    if (pRolls == 20) 
    {
        rpslsWon();
    } 
    else 
    {
        //increment pRolls by 1
        pRolls++;
    }
}

function score():void 
{ 
    //if player wins, his/her score increases by 1
    if (msgDisplay.text == "Yay! You win!") 
    {
        pScore = pScore + 1
        pScoreDisplay.text = pScore.toString();
    //if player loses, computer score increases by 1
    } 
    else if (msgDisplay.text == "Boo! Stuart wins!") 
    {
        gScore = gScore + 1
        gScoreDisplay.text = gScore.toString();
    //if neither wins, their scores remain unchange
    } 
    else 
    {
        pScore = pScore
        gScore = gScore
    }
}

function rpslsWon():void 
{
    gameOverBananaMC.visible = true;
    bananaWinLose.visible = true;
    bananaWinLose.text = "Kampai! You are totally bananas!! \nYour Score: " + pScore;
    toMenuBtn.visible = true;
    rollAgainBtn.visible = true;
    toMenuBtn.addEventListener(MouseEvent.CLICK, Click_backtoMain);
    rollAgainBtn.addEventListener(MouseEvent.CLICK, backtoBanana);
}

function backtoBanana():void
{
    pScore = 0;
    gotoAndStop("menu");
    gotoAndStop("banana");
}

so the error appears in the function backtoBanana(), I can't seem to fix it. Can someone help me? Thanks alot.

Was it helpful?

Solution

The callback function for the MouseEvent-listener will be passed a MouseEvent. Change

function backtoBanana():void

to

function backtoBanana(event:MouseEvent):void

just like your other callback function:

function Click_backtoMain(event:MouseEvent):void
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top