为什么我得到 1136:参数数量不正确。预期 0

why am I getting 1136: Incorrect number of arguments. Expected 0

开始问题:我在 var timer:Timer=new Timer(10000,1); 处不断收到错误 1136。我不确定这是电脑错误还是什么。我知道你为定时器设置了(延迟,然后是时间间隔),但它仍然给我错误信息。

更新:我上传了原始代码的全部代码 post 看看是否有人能发现任何错误。我的计时器应该是正确的,但我的程序仍然出现错误 1136,甚至 运行。当我确实取出计时器时,代码工作得很好。 有没有其他办法。实现一个计时器让游戏停止并说游戏结束?

package  {

import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.utils.Timer;
import flash.text.*; 

public class Duckhunt extends MovieClip 
{
    private var player1:Player;
    private var counter:Number;
    private var points:Number;
    private var cursor:Cursor;
    private var duckArmy:Vector.<Duck1>;
    private var duckArmy2:Vector.<Duck2>;
    private var duckCounter:Number;
    private var duckCounter2:Number;
    private var count:Number=10;
    private var timer:Timer;
    //var countDownDec:Number=1;
    //private var myTimer:Timer=new Timer(0,count);


    public function Duckhunt() 
    {
        //# constructor code

        // creates a new five-second Timer 
        var timer:Timer=new Timer(10000,1);

        //add event listner to timer
        timer.start();

        //starts the timer
        //myTimer.start();

        player1=new Player();
        player1.x = 375; player1.y = 400; addChild(player1);

        //cursor crosshair
        cursor= new Cursor();
        cursor.x = 400; cursor.y = 200; addChild(cursor);

        //add enemy
        duckArmy=new Vector.<Duck1>();

        for(var i:Number = 0; i < 30; i++)  
        {
            var duck:Duck1 = new Duck1(400,0);
            duckArmy.push(duck);
            duck.y = 450;
            stage.addChild(duck);
            duck.gotoAndPlay("fly");
            duck.addEventListener(MouseEvent.CLICK, hitEnemy);

        }//end duck1 army

        //add second second enemy
        duckArmy2=new Vector.<Duck2>();

        for(var j:Number=0;j<30;j++)
        {
            var duck2:Duck2 = new Duck2(0,400);
            duckArmy2.push(duck2);
            duck2.x = -900;
            stage.addChild(duck2);
            duck2.gotoAndPlay("fly");
            duck2.addEventListener(MouseEvent.CLICK, hitEnemy);
        }//end duck2 army

        duckCounter = duckCounter2 =counter = points = 0;
        addEventListener(Event.ENTER_FRAME, frameMovement);

    }//end constructor


}//end class


}//end package

如果您已将 :Timer 对象声明为 publicprivate 变量:

private var timer:Timer;

无需在后续函数中声明另一个新变量(同名);

var timer:Timer=new Timer(10000,1); //creates a new 2nd var.. causes error..
timer.start();

应该是:

timer = new Timer (10000,1); //uses existing private var
timer.start();

另请注意:

timer variable 名称与 Timer datatype 名称太相似,考虑更改名称的拼写以避免使用内置系统名称 "clashing"。永远不要 var int :int = 0;.

尝试命名为 _timer :Timer; 甚至 myTimer :Timer;