flash - 错误1136 : incorrect number of arguments. Expected 1

标签 flash actionscript-3 error-handling

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

外部作为文件的第一个“更新”功能可以工作,但是我在第二个外部文件中添加的实例给我带来了错误...(后面还有第三个可以工作的错误)

注意:代码本身是fla文件的外部as文件。 (我检查了一下,所有内容都正确链接到他们各自的外部文件。

这是整个功能代码。 (仍在处理中。)
        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

最佳答案

如果您要在不提供任何参数的情况下调用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: Error #1009: Cannot access a property or method of a null object reference.

关于flash - 错误1136 : incorrect number of arguments. Expected 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8904119/

相关文章:

javascript - 如何使用 Chrome 扩展程序的 ContentScript 更改 flashvar?

flash - 使用 Selenium 和 Webdriver 截取 flash 对象的屏幕截图

javascript - swf 文件到 html-css-js

flash - 加密 as3 flash .swf

html - Node.js 的 Vimeo-API HTML 错误 'Sorry. Vimeo will be right back'

flash - Haxe未检测到库

flash - 查找两种已知颜色之间的颜色百分比值

actionscript-3 - addEventListener(和 removeEventListener)是否堆栈?

r - 避免让设备继续使用

php - 调用 PHP 函数时如何防止显示错误