未定义属性错误1120移动函数?

时间:2015-12-11 05:49:21

标签: actionscript-3 flash flash-cs5

我非常非常非常新闻,而且我已经非常努力地想到这一点,但它没有用。我一直得到同样的错误:" 1120访问未定义的属性goGame"在第96行和" 1136预期的参数数量不正确1"在第82行。

我知道这两个错误都与我的函数的排序有关,但我发现当我将函数移动到监听器前面时,会出现更多错误要求同样的事情,并且唯一的方法我可以解决那些将它们移到彼此面前等等。所以我有点卡住了。帮助将非常感谢!

package 
{

    import flash.display.*;
    import flash.events.*;
    import flash.ui.*;
    import fl.motion.MotionEvent;
    import flash.utils.Timer;
    import flash.utils.*;

    public class StartGame extends MovieClip
    {
        var questions: Array=new Array();
        var correctAnswers: Array=new Array("blue","Russia","10","stone","true","hydrogen and oxygen","Rapunzel","magician","The Mona Lisa","string","12","mammal","lightning bolt","lacrosse","do");
        //Creates am array used for the Quiz Time function
        var i = 0;
        //used to track player's movements on board
        var lives = 3;
        //the # of lives given at the beginning of the game
        var collide: Boolean;
        var myTimer: Timer = new Timer(1000, 60);
        //used for timer in Storming the Castle Game
        var count = 0;
        //used to manage chibiKing movements







            //stage.addEventListener(Event.ENTER_FRAME,onFrameLoop);
            //loops frames card so animation plays
            //function to get to the master instructions page

            //function to get the the main board



        function randomNumber(){
            var number=Math.round(Math.random()*5)+1; 
            return number;
        }//end randomNumber function    


        function StartGame() 
        {
            instructionsButton.addEventListener(MouseEvent.CLICK, masterInstructions);
            //listener on instructions button to open the instructions page
            goButton.addEventListener(MouseEvent.CLICK, playGame);
            //listener on the first play button to go to the game board


        }//end StartGame function
        function masterInstructions (event:MouseEvent) {
            gotoAndPlay(2);
            //takes you to the master instructions page
            goButton2.addEventListener(MouseEvent.CLICK, playGame);
            //listener on the first play button to go to the game board

        }// end masterInstructions function

        function rollDie (event:MouseEvent) {
            goRollButton.removeEventListener (MouseEvent.CLICK, rollDie);
            //makes player unable to click roll button after pressing once
            goRollButton.visible = false;
            //removes visiblity of the roll button one clicked
            goButtonGame.visible = true;
            //makes game button appear so player can proceed to game
            var currentRoll=randomNumber();
            //randomly rolls a number between 1 and 6
            outputNumber.text=String(currentRoll);
            //displays the number rolled 
            var newMoves = i + currentRoll*10;
            //moves player forward, i being the number already moved
            //roll multipled by ten for frame movements of tween
            gameboy.gotoAndStop(newMoves);
            //player stops at the new position
            i = newMoves; 
            //i now changed to rolled number
            if (i<=300) {
                bossGame();
            }//if player gets to end of board, automatically start boss game

        }//end rollDie function

        function playGame (event: MouseEvent) {
            gotoAndPlay(3);
            //goes to main board game
            livesOutput.text=String(lives);
            //displays the 3 of lives the player has in the output box
            gameBoard.addEventListener(MouseEvent.CLICK, girlJumps);
            //event listener for a pop up
            goRollButton.addEventListener(MouseEvent.CLICK, rollDie);
            //when pressed, button calls die roll function
            goButtonGame.addEventListener(MouseEvent.CLICK, goGame);
            //when pressed, chooses a random mini game 
            ball.addEventListener(MouseEvent.MOUSE_DOWN,ballStartDrag);
            ball.addEventListener(MouseEvent.MOUSE_UP, ballEndDrag); 
            bear.addEventListener(MouseEvent.MOUSE_DOWN, bearStartDrag);
            bear.addEventListener(MouseEvent.MOUSE_UP, bearEndDrag);
            //functions to create drag and drops for objects on stage game board
            goButtonGame.visible=false;
            //does not display go button so player must roll dice before playing game

        }//end playGame function

        function ballStartDrag (evt:MouseEvent) {
            ball.startDrag();

        }//end ballStartDrag function

        function bearStartDrag (evt:MouseEvent) {
            bear.startDrag();
        }//end bearStartDrag function

        function ballEndDrag (evt:MouseEvent) {
            ball.stopDrag();
        }//end ballEndDrag function

        function bearEndDrag (evt:MouseEvent) {
            bear.stopDrag();
        }//end bearEndDrag function

        function girlJumps (evt:MouseEvent) {
            girlJump.gotoAndPlay(2);
            //has character on board to appear by playing tween
        }//end girlJumps function

        function bossGame (event:KeyboardEvent) {

            stage.addEventListener( KeyboardEvent.KEY_DOWN, finalBoss);
            //listener to player movement when keyboard is pressed

            addEventListener(Event.ENTER_FRAME,movefireball);
            //listener to move the fireball

            stage.addEventListener(Event.ENTER_FRAME, collision);
            //listener to collisions between symbols on stage

            livesBoss.text=String(lives);
            //displays number of lives in text box

            fireball.height = 100;
            fireball.width = 100;
            fireball.x=40
            fireball.y=40
            fireball.xVelocity=8;
            fireball.yVelocity=8;
            //sets fireball parameters


        }//end bossGame function

        function movefireball (evt: Event) {
            fireball.x +=fireball.xVelocity;
            fireball.y +=fireball.yVelocity;
            //creates speeds of fireball
            checkfireballtoWall();
            //calls function

            var move1:Number=Math.ceil(Math.random()*stage.stageWidth) + 1;
            var move2:Number=Math.ceil(Math.random()*stage.stageWidth) + 1;
            //movements randomly created for king's movements

            if (count%100 == 0) {
                chibiKing.x= move1;
                chibiKing.y= move2;
                //reassigns chibiKing's movements
            }
            count++;
            //adds to count after so many seconds
        }//end movefireball function

        function checkfireballtoWall(){
            const TOP: Number= 50;
            const BOTTOM: Number= stage.stageHeight;
            const LEFT: Number= 50;
            const RIGHT: Number= stage.stageWidth - 50;
            const REVERSE: int = -1;
            //limits to fireball's movements

            if (fireball.y<TOP) {
                fireball.y=TOP;
                fireball.yVelocity*=REVERSE;
            }
            else if (fireball.y>BOTTOM) {
                fireball.y=BOTTOM;
                fireball.yVelocity*=REVERSE;
            }
            if (fireball.x<LEFT) {
                fireball.x=LEFT;
                fireball.xVelocity*=REVERSE;
            }
            else if (fireball.x>RIGHT) {
                fireball.x=RIGHT;
                fireball.xVelocity*=REVERSE;
            }
            //reassignes fireball's direction if fireball hits a certain area
        }//end checkfireballtoWall function

        function finalBoss (evt: KeyboardEvent) {
            if( evt.keyCode == Keyboard.LEFT )  
                {player.x = player.x - 6;   
            }
            else if( evt.keyCode == Keyboard.UP )  
                {player.y = player.y - 6;    
            }
            else if( evt.keyCode == Keyboard.RIGHT )  
                {player.x = player.x + 6; 
            }
            else if( evt.keyCode == Keyboard.DOWN )  
                {player.y = player.y + 6;
            }//allows player to move via keyboard control
        }//end finalBoss function

        function collision (evt: Event) {
            if (player.hitTestObject(chibiKing)) {
                gotoAndPlay(14);
                //if player hits the king, automatically go to win game screen
            if (player.hitTestObject(fireball)) {
                lives = lives - 1;
                //if player hits fireball, lose a life
                if (lives == 0) {
                    gotoAndPlay(11);}
                    //if lives equal to zero, go automatically to lose game screen
                livesBoss.text=String(lives);
                //display the lives remaining the text box
                }
        }//end collision function

        function dragonBattle (event:KeyboardEvent) {
                //inset Dragon Battle code
        }//end dragonBattle function







        function goGame (event:MouseEvent) {
            var gameChoose=randomNumber();
            //randomly chooses a game to play from the existing mini games
            if (gameChoose==1 || gameChoose == 2) {
                gotoAndPlay(4);
                //game 1 start screen
                goButton3.addEventListener (MouseEvent.CLICK, stormingTheCastle);
                //listener to go to Storming the Castle Game
            }//end goGame function

            else if (gameChoose==3 && correctAnswers.length>0) {
                gotoAndPlay(7)
                //quiz time start screen
                quizTimeButton.addEventListener (MouseEvent.CLICK, quizTime);
                //quiz time start

            }
            else {gotoAndPlay(6);
                //game 2 start screen
                goButton5.addEventListener (MouseEvent.CLICK, dragonBattle);
                //listener to start game 2
                //wizardess.addEventListener (MouseEvent.CLICK, wizardessMagic);}

            }
        }//end goGame function

        function quizTime (event:MouseEvent) {

            questions [0]= "What colour is the sky?";
            questions [1]= "What is the world's biggest country in land mass?";
            questions [2]= "Do Re Mi Fa So La Ti...";
            questions [3]= "How many tentacles does a squid have?";
            questions [4]= "In Greek Mythology, looking into Medusa's eyes would turn you to...?";
            questions [5]= "True or False: Winnipeg has a hockey team.";
            questions [6]= "Water is made out of...?";
            questions [7]= "Which princess is the star of Disney's movie 'Tangled'?";
            questions [8]= "Harry Houdini was famous for being a(n)...?";
            questions [9]= "Leonardo Da Vinci famously painted what?";
            questions [10]= "What type of instrument is a sitar?";
            questions [11]= "How many are in a dozen?";
            questions [12]= "Humans are...?";
            questions [13]= "Harry Potter is famous for having a scar shaped as what on his forehead?";
            questions [14]= "What is the national sport of Canada?";
            //creates questions to go with answers created in startGame function    

            questionBox.text=questions[questions.length];
            //displays the question at the end of the array

            answerQuizTime.addEventListener(MouseEvent.CLICK, quiz);
            //button to proceed to get quiz marker  


        }//end quizTime function

        function quiz (evt:MouseEvent){
            var userAnswer=String(answerInput.text);
            //saves the user's answer in userAnswer variable
            if (userAnswer==correctAnswers[questions.length]) {
                questions.pop();
                //removes question from end of array
                lives = lives + 1;
                //adds life to player's total lives
                gotoAndPlay(9);
                //goes to minigame win screen
            }
            else {
                questions.pop();
                //removes question from end of array
                lives = lives - 1;
                //removes life from player's total lives
                gotoAndPlay(10);
                //goes to minigame lose screen
            }
        }//end quiz function

        // handler function for the Arrow Keys to move Player across the stage
        function movePlayer(evt: KeyboardEvent) {

            // if key is right arrow, move Player to the right
            if (evt.keyCode == Keyboard.RIGHT) {
                Player.x += 20;

            // if key is left arrow, move Player to the left
            } else if (evt.keyCode == Keyboard.LEFT) {
                Player.x -= 20;
            }
        }//end movePlayer function



        function stormingTheCastle (event:MouseEvent) {
            // add a listener for a Frame Event
            stage.addEventListener(Event.ENTER_FRAME, onFrameLoop);

            // add the listener for Keyboard events to the stage
            stage.addEventListener(KeyboardEvent.KEY_DOWN, movePlayer);

            // create a custom speed property for each knight
            //start timer
            knight1.velocity = 4;
            knight2.velocity = 6;
            knight3.velocity = 3;
            knight4.velocity = 5;
            collide = false;
            myTimer.start();
        }//end stormingTheCastle function


        // each time frame 1 plays, move each knight
        //continues if no collision and count less than 60
        //return each night to top if it reaches the bottom
        function onFrameLoop(evt: Event) {
            if (collide == false && myTimer.currentCount < 60) {
                if (knight1.y > 292.2)
                    {knight1.y = 42.45;}
                if (knight2.y > 292.2)
                    {knight2.y = 42.45;}
                if (knight3.y > 292.2)
                    {knight3.y = 42.45;}
                if (knight4.y > 292.2)
                    {knight4.y = 42.45;}

                //move knights down by its speed property amount
                knight1.y = knight1.y + knight1.velocity;
                knight2.y = knight2.y + knight2.velocity;
                knight3.y = knight3.y + knight3.velocity;
                knight4.y = knight4.y + knight4.velocity;

                //trace timer count
                trace(myTimer.currentCount);

                //if Player is hit by a knight collision is true
                if (knight1.hitTestObject(Player) == true) {
                    collide = true;
                    trace("test");
                }
                if (knight2.hitTestObject(Player) == true) {
                    collide = true;
                }
                if (knight3.hitTestObject(Player) == true) {
                    collide = true;
                }
                if (knight4.hitTestObject(Player) == true) {
                    collide = true;
                }
                else {
                if (lives == 0) {
                    gotoAndPlay(11);}
                //trace Game Over when collision is true
                trace("GAME OVER");

                gotoAndPlay(10);

                }

        } //end onFrameLoop function


    }

                }//end startGame function

    }//end class function

}//end package

1 个答案:

答案 0 :(得分:0)

在类文件中,函数和var定义的顺序不是问题(除了匿名和嵌套函数,你应该避免使用它们。)

让我们从第82行开始。您拨打bossGame(),但是当您查看该功能时,您已对其进行了定义,因此需要参数:

function bossGame (event:KeyboardEvent)

希望您将KeyboardEvent传递给该功能。虽然我不确定为什么因为看这个函数它似乎与键盘输入无关,也不以任何方式使用该事件。

所以,取出参数:

function bossGame()

或者,通过给它一个默认值使其成为可选项:

function bossGame(event:KeyboardEvent = null)

第二个错误。您的goGame函数实际上嵌套在另一个函数collision()中,因此除了碰撞函数内部之外它没有作用域。如果您希望能够在该功能之外访问它,那么您应该将其分解。

顺便说一下,你在关闭功能括号旁注释通常是不正确的,因此很难阅读你的代码。