错误1136:参数数量不正确。预期1

时间:2012-01-18 01:39:01

标签: flash actionscript-3 error-handling

        //Handle game logic
        mcPlayer.update();
        //create question
        mcMathQu.update(); 

外部文件的第一个“更新”功能正常工作,但我在第二个外部文件中添加了实例,它给了我那个错误......(背后有第三个也有效)

注意:代码本身是外部文件的fla文件。 (我检查过,所有内容都与文件中的个人外部链接正确。

这是整个功能代码。 (仍在进行中。)

        public function update(evt:Event)
    {
        //This is the game loop     


        //Handle user input
        if (right)
        {
            mcPlayer.moveRight();
        }
        else if (left)
        {
            mcPlayer.moveLeft();
        }
        else
        {
            mcPlayer.stopMoving();
        }

        if (jumping && !mcPlayer.isInAir())
        {
            mcPlayer.jump();
        }
        //reset jump
        jumping = false;

        //Handle game logic
        mcPlayer.update();
        //create question
        mcMathQu.update(); 

        for (var i = aliensArray.length - 1; i >= 0; i--)
        {
            aliensArray[i].update();
        }

        //Check for collision between player and platforms
        if (mcPlayer.isFallingDown())
        {
            for (var j = platformsArray.length - 1; j >= 0; j--)
            {
                if (platformsArray[j].hitTestObject(mcPlayer.hitBox))
                {
                    mcPlayer.y = platformsArray[j].y;
                    mcPlayer.hitFloor(platformsArray[j]);

                    //Exit the loops
                    break;
                }
            }
        }

        //Check for collision between player and aliens
        for (var k = aliensArray.length - 1; k >= 0; k--)
        {
            if (aliensArray[k].hitTestObject(mcPlayer.hitBox))
            {
                if (mcPlayer.isFallingDown())
                {
                    //player jumped on it
                    removeChild(aliensArray[k]);
                    aliensArray.splice(k,1);
                }
                else
                {
                    //player is hit
                    gotHit();
                }
            }
        }

        //Check for Game Over
        if (life <= 0)
            gameOver();

        //Handle display
        txtLife.text = String(life);            

        //Check for collision between portals and player
        if (currPortal.hitTestPoint(mcPlayer.x, mcPlayer.y))
        {
            if (currentLabel == "stage1")
                gotoAndStop("stage2");
            else if (currentLabel == "stage2")
            {
                removeEventListener(Event.ENTER_FRAME, update);
                gotoAndStop("win");
            }
        }
    }

和外部代码

package Game{
//Add in your import statements here
import flash.display.*;
import flash.events.*;
import flash.utils.*;

//...

public class Maths extends MovieClip
{
    //Add in your class variables here
    //private var score:Number;
    private var operand1:Number;
    private var operand2:Number;
    private var mathsign:String;
    private var rdmSign:int;
    private var startNewGame:Boolean; 
    //private var count:Number;
    //private var myTimer:Timer;
    //...
    /* add new var, and put it as random 4 different int, 
    than use it to SET mathsign as + - / x ...  
    dun forget the 60 sec timer. 
    and minus 10 sec if ans wrongly . 
    and 1 min only 30 questions . :D
    note : add in a end game menu + big big score :DDD 
    and a start game one also. 
    */
    public function MathsQuiz()
    {

    }

    public function Maths()
    {


        //score = 0; 
        operand1 = 0;
        operand2 = 0;
        startNewGame = true;
        //count = 60 ; 
        //myTimer = new Timer(1000,count);



        //Get the game loop to execute
        addEventListener(Event.ENTER_FRAME,update);
        stage.addEventListener(KeyboardEvent.KEY_DOWN, checkAnswer);
        //myTimer.addEventListener(TimerEvent.TIMER, ticktock);
        //myTimer.start();  


    }




   // private function ticktock(event:TimerEvent):void 
    //{
   //     txtCountdown.text = String((count)-myTimer.currentCount);
    //}

    private function checkAnswer(evt:KeyboardEvent) 
    {
        if (evt.keyCode == 13)
        {
            if (mathsign == "+" && txtResult.text == String(operand1 + operand2))
            {
                //score += 10;
            }
            else if (mathsign == "-" && txtResult.text == String(operand1 - operand2))
            {
                //score += 10;
            }
            else if (mathsign == "x" && txtResult.text == String(operand1 * operand2))
            {
                //score += 10;
            }
            else if (mathsign == "÷" && txtResult.text == String(operand1 / operand2))
            {
                //score += 10;
            }
            else
            {
                //score -=5;
                //count -=10;
            }
            startNewGame = true;
            txtResult.text = "";
        }

    }

    public function update(evt:Event)
    {

        //die
        //if (txtCountdown.text <= "0")
        //{
            //score = 0;
            //count = 60;
            //startNewGame = true;
        //}
        //random sign is random. 


      if(rdmSign == 1)
      {
           mathsign = "+";
      }
      else if(rdmSign == 2)
      {
           mathsign = "-";
      }
      else if(rdmSign == 3)
      {
           mathsign = "x";
      }
      else if(rdmSign == 4)
      {
           mathsign = "÷";
      }


        //Handle user input


        //Handle game logic
        if (startNewGame == true)
        {
            var max = 12;
            var min = 0;
            operand1 = Math.floor(Math.random()*(max-min+1))+min;
            operand2 = Math.floor(Math.random()*(max-min+1))+min;
            rdmSign = Math.floor(Math.random() *4 + 1);
            startNewGame = false;
        }
        //Handle display
        txtOperand1.text = String(operand1);
        txtOperand2.text = String(operand2);
        txtMathsign.text = String(mathsign);
        //txtScore.text = String(score);
    }       

}//end class    
    }//end package

1 个答案:

答案 0 :(得分:3)

如果您打算在没有给出任何参数的情况下致电update(),只需让您的第一个参数(evt)的默认值为null

public function update(evt:Event = null)

更新此方法时要小心;如果你在里面的任何地方使用evt,你必须确保包裹if(evt != null)或类似的,例如:

public function update(evt:Event = null):void
{
    if(evt != null)
    {
        trace(evt.target);
    }
}

否则你会受到一些精彩的轰炸:

  

TypeError:错误#1009:无法访问null的属性或方法   对象参考。

相关问题