0

所以我一直在开发一款名为“剪刀石头布蜥蜴史波克”的游戏。

我收到此错误:ArgumentError:错误 #1063:FlashGame_fla::MainTimeline/backtoBanana() 上的参数计数不匹配。预期为 0,得到 1。

这是我的主要代码:

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");
}

所以错误出现在函数 backtoBanana() 中,我似乎无法修复它。有人能帮我吗?非常感谢。

4

1 回答 1

1

MouseEvent-listener 的回调函数将传递一个MouseEvent. 改变

function backtoBanana():void

function backtoBanana(event:MouseEvent):void

就像您的其他回调函数一样:

function Click_backtoMain(event:MouseEvent):void
于 2013-10-23T15:16:44.090 回答