1180:调用可能未定义的方法数组

时间:2014-03-23 17:46:44

标签: arrays actionscript-3 memory methods flash-cs6

问候语, 我刚刚开始学习脚本,并试图为学校项目制作记忆游戏。我自己能够解决大部分问题,但现在我偶然发现了一个我无法解决的错误:/

  

1180:在第80行调用可能未定义的方法数组   功能setupGame() cardValues = new arrays();

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()
    {

    }

    //All Start Functions
    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();

        //Shuffle
        cardValues = new Array();
        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;  
        }

        //Deal
        for (var j=0; j<cardValues.length; j++)
        {
            cards[j].hiddenValue = cardValues[j];
            cards[j].addEventListener(MouseEvent.CLICK, flipCard);
        }

        addEventListener(Event.ENTER_FRAME,update);

        stage.focus = this;
    }

    private function setupGame()
    {
        cardValues = new arrays();
        //Check the classes of the movieclips and push them into the 
        //appropriate arrays
        for (var i=0; i< MovieClip(root).numChildren; i++)
        {
            var object = MovieClip(root).getChildAt(i);

            if (object is Card)
            {
                cards.push(object);
            }
            cardValues.push("card"+(cardValues+length +1));
            var m = cardValues.length +1;
            cardValues.push("card"+m);
            cardValues.push("card"+m);
        }
    }

    private function gotoStartGame(evt:MouseEvent)
    {
        btnStartGame.removeEventListener(MouseEvent.CLICK, gotoStartGame);
        btnHowToPlay.removeEventListener(MouseEvent.CLICK, gotoHowToPlay);
        gotoAndStop("level1");
    }

    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
        {
            //this is the third card clicked,
            //means the cards clicked do not match
            //reset them
            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)
        {
            //check if same
            if (firstCard.hiddenValue == secondCard.hiddenValue)
            {
                removeChild(firstCard);
                removeChild(secondCard);

                score += 10;

                firstCard = null;
                secondCard = null;
            }
            else if (doLoseLife)
            {
                life--; //considered as one attempt once both cards are flipped
                doLoseLife = false;
            }
        }

        if (currentLabel == "level1")
        {
            if (score >= 70)
            {
                gotoAndStop("level2")
            }
        }
        else if (currentLabel == "level2")
        {
            if (score >= 150)
            {
                gotoAndStop("level3")
            }
        }
        else if (currentLabel == "level3")
        {
            if (score >= 150)
            {
                gotoWin = true;
            }
        }   
        if (life <= 0)
        {
            gotoLose = true;
        }
    }

    private function handleDraw()
    {
        //Handle display
        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");
    }

    //Misc Functions
    private function resetGame()
    {
        for (var i in cards)
            cards[i].gotoAndStop("back");
    }       
  } 
}

1 个答案:

答案 0 :(得分:0)

arrays不是一个类,您可能想创建一个Array

查看您的错误实际上告诉您需要知道的一切:

1180: Call to a possibly udefined method arrays on line 80

说你试图在第80行调用一个名为arrays的不存在的方法。我不明白为什么人们担心编译器的错误和警告,他们的意思是帮助你,你只是了解英语。
如果你不理解错误,那么有错误代码,在谷歌上搜索错误代码,你会找到一个解决方案。 :)