Question

Greeting, I just started to learn scripting and am trying to make a memory game for a school project. I have been able to solve most of the issues myself but now I stumbled a ERROR i can't fix :/

1180: Call to a possibly undefined method arrays on line 80, in the Function setupGame() the 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");
    }       
  } 
}
Was it helpful?

Solution

arrays is not a class, you probably wanted to create an Array.

See your error actually tells you everything you need to know:

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

Says that you are trying to call a not existing method which is called arrays on line 80. I don't understand why people fear the errors and warnings of the compilers, they meant to help you, you just got to understand english.
If you don't understand the error, then there is the error code, search for the error code on google and you will find a solution. :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top