错误1136:参数数量不正确。预计0

时间:2015-03-13 08:53:40

标签: actionscript-3 flash flash-cs6

任何人都可以告诉我这段代码有什么问题...如何解决这段代码我使用这段代码让怪物移动到检查站......但所有的检查点都得到了22-30号线的警告:参数数量不正确。预期为0。

package Game
{
    import flash.display.MovieClip;
    import flash.events.*;
    import flash.geom.*;    

    public class Monster extends MovieClip
    {       
        public var currLife:Number;
        private var maxLife, gold, speed, currIndex, slowTimer:Number;
        private var checkPoints:Array;

        public function Monster()
        {
            maxLife = C.MONSTER_LIFE;
            currLife = maxLife;
            speed = C.MONSTER_SPEED;

            currIndex = 0;

            checkPoints = new Array();
            checkPoints.push(new Point(85,140));
            checkPoints.push(new Point(85,320));
            checkPoints.push(new Point(325,320));
            checkPoints.push(new Point(325,200));
            checkPoints.push(new Point(265,200));
            checkPoints.push(new Point(265,80));
            checkPoints.push(new Point(505,80));
            checkPoints.push(new Point(505,380));
            checkPoints.push(new Point(630,380));
        }

        public function update()
        {
            var finalSpeed:Number;

            if (slowTimer > 0)
            {
                finalSpeed = speed / 2;
                slowTimer--;
            }
            else
                finalSpeed = speed;

            if (currIndex < checkPoints.length)
            {
                //move in the direction of the checkpoint
                if (this.x < checkPoints[currIndex].x)
                    this.x += Math.min(finalSpeed, Math.abs(this.x - 
                                                checkPoints[currIndex].x));
                else if (this.x > checkPoints[currIndex].x)
                    this.x -= Math.min(finalSpeed, Math.abs(this.x - 
                                                checkPoints[currIndex].x));

                if (this.y < checkPoints[currIndex].y)
                    this.y += Math.min(finalSpeed, Math.abs(this.y - 
                                                checkPoints[currIndex].y));
                else if (this.y > checkPoints[currIndex].y)
                    this.y -= Math.min(finalSpeed, Math.abs(this.y - 
                                                checkPoints[currIndex].y));

                if ((this.x == checkPoints[currIndex].x) &&
                    (this.y == checkPoints[currIndex].y))
                {
                    currIndex += 1;
                }
            }

            //display
            if (currLife > 0)
                mcLifeBar.width = Math.floor((currLife/maxLife)*
                                                    C.LIFEBAR_MAX_WIDTH);
            else
                mcLifeBar.width = 0;
        }

        public function takeDamage(amtDamage)
        {
            if (this.currLife <= 0)
                return;

            this.currLife -= amtDamage;

            if (this.currLife <= 0)
            {
                this.gotoAndPlay("death");
            }
        }

        public function slowDown(amt)
        {
            slowTimer = amt;
        }

        public function hasReachedDestination()
        {
            return (this.currIndex == checkPoints.length);
        }
    }
}

请帮我解决这个问题...我只是AS3中的菜鸟

我在GameController.as中使用上面的代码 这是GameController的更新

public function update(evt:Event)
        {
            //Update the mobs
            if ((currWave < maxWave) && (monsters.length == 0))
            {
                currWave++;

                //spawn the monsters
                spawnWave(currWave);
            }

            for (i=monsters.length - 1; i >= 0; i--)
            {
                if (monsters[i].currLife > 0)
                {
                    monsters[i].update();
                }

                //Check if monster reaches the end of their path
                if (monsters[i].hasReachedDestination())
                {
                    monsters[i].gotoAndStop("remove");
                    life -= 1;
                    currGold -= C.MONSTER_GOLD;
                }

                if (monsters[i].currentLabel == "remove")
                {
                    mcGameStage.removeChild(monsters[i]);
                    monsters.splice(i,1);

                    //Award Gold
                    currGold += C.MONSTER_GOLD;
                }
            }

            //Update all the towers
            for (i in towers)
            {
                towers[i].update();
            }

            //Update all the bullets
            for (i=bullets.length - 1; i >= 0; i--)
            {               
                bullets[i].update();

                if (bullets[i].currentLabel == "remove")
                {
                    mcGameStage.removeChild(bullets[i]);
                    bullets.splice(i,1);
                }
            }

            //******************
            //Handle Display
            //******************            
            //Display new Score
            mcGameUI.txtLife.text = String(life);
            mcGameUI.txtGold.text = String(currGold);
            mcGameUI.txtWave.text = String(currWave) + " / " +  String(maxWave);

            //Check for end game
            if (life <= 0)
            {
                gameOver();

                //stop all subsequent code in this update to run
                return;
            }
            else if ((currWave == maxWave) && (monsters.length == 0))
            {
                gameWin();
            }
        }

    private function spawnMonster(xPos, yPos)
    {
        var monsterToSpawn = new Monster();
        monsterToSpawn.x = xPos;
        monsterToSpawn.y = yPos;
        monsters.push(monsterToSpawn);
        mcGameStage.addChild(monsterToSpawn);
    }

    private function spawnWave(currWave)
    {
        if (currWave == 1)
        {
            spawnMonster(C.MONSTER_START_X, C.MONSTER_START_Y);
        }
        else if (currWave == 2)
        {
            for (i = 0; i < 2; i++)
            {
                spawnMonster(C.MONSTER_START_X - 40*i, C.MONSTER_START_Y);
            }
        }
}

1 个答案:

答案 0 :(得分:1)

您好,我不明白为什么会收到此错误,但这可以帮到您,

尝试使用以下代码而不是Point();

var checkPoints:Array=new Array({x:85,y:140},
            {x:85,y:320},
            {x:325,y:320},
            {x:325,y:200},
            {x:265,y:200},
            {x:265,y:80},
            {x:505,y:80},
            {x:505,y:380},
            {x:630,y:380}
            );