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

时间:2018-05-17 08:36:43

标签: actionscript-3

开始问题:我在var timer上不断收到错误1136:Timer = new Timer(10000,1);.我不确定它是否是计算机错误或者是什么。我知道你为Timer设置了(延迟,然后是时间间隔),但它仍然给我错误信息。

更新:我从原始帖子上传了整个代码,看看是否有人发现任何错误。我的计时器应该是正确的,但我仍然在我的程序上得到错误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

1 个答案:

答案 0 :(得分:0)

如果您已将:Timer对象声明为公开私有变量:

private var timer:Timer;

在以后的函数中不需要再声明另一个新变量(具有相同名称);

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

Shoud be:

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

另请注意:

timer 变量名称与Timer 数据类型名称太相似,请考虑更改名称的拼写以避免与内置“冲突” -in系统名称。永远不要var int :int = 0;

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