0

大家好,我是编程新手,我正在关注As3 Flash 游戏的教程

我遇到了一个编写它的代码

var ourShip:ship = new ship(stage);

但它给出了一个错误

1136: Incorrect number of arguments.  Expected 0.

我相信这个错误是对的,但是关于教程很棒的评论呢!

包含此代码的 as 文件中有

package
{
    //list of our imports these are classes we need in order to
    //run our application.
    import flash.display.MovieClip;
    import flash.display.Stage;

    //our Engine class it extends MovieClip
    public class engine extends MovieClip
    {

        //our constructor function. This runs when an object of
        //the class is created
        public function engine()
        {


            //create an object of our ship from the Ship class
            var ourShip:ship = new ship(stage);
            //add it to the display list
            stage.addChild(ourShip);
            ourShip.x = stage.stageWidth / 2;
            ourShip.y = stage.stageHeight / 2;
        }

    }

}

还要告诉我,我从

package come.asgamer.....{}

package utils{}

我这样做是因为我创建了一个名为 utils 的文件夹,其中包含感知动作脚本

我想也许与此有关的问题

顺便说一句,如果我改变

var ourShip:ship = new ship(stage);

var ourShip:ship = new ship();

没有结果,这意味着 Flash 播放器将船显示在中间

运送动作脚本文件:

package
{

    import flash.display.MovieClip;
    import utils.KeyObject;
    import flash.ui.Keyboard;
    import flash.display.Stage;
    import flash.events.Event;


    public class ship extends MovieClip
    {
    private var stageRef:Stage;
    private var key:KeyObject;
    public function Ship(stageRef:Stage)
    {
    this.stageRef = stageRef;
    key = new KeyObject(stageRef);

    addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
    }
    public function loop(e:Event) : void
        {
        if (key.isDown(Keyboard.LEFT)) 
                x -= 2;
            else if (key.isDown(Keyboard.RIGHT))
                x += 2;

            if (key.isDown(Keyboard.UP))
                y -= 2;
            else if (key.isDown(Keyboard.DOWN))
                y += 2;
        }
    }
}

注意:我完成了教程

4

1 回答 1

0

大写ship; 这就是他们在教程中所做的。试试看它是否有效。

您使用的类可能与您认为正在使用的类不同。他们提供的类 is Ship, not ship,并且在他们提供的代码中Ship,构造函数实际上确实有一个参数:

package com.asgamer.basics1{

    import flash.display.MovieClip; import flash.display.Stage;
    import com.senocular.utils.KeyObject;
    import flash.ui.Keyboard;

    public class Ship extends MovieClip {

        private var stageRef:Stage;
        private var key:KeyObject;

        public function Ship(stageRef:Stage)
        {
            this.stageRef = stageRef;
            key = new KeyObject(stageRef);
        }

    }

}

如果大写ship不起作用,那么您正朝着正确的方向前进,但可能还有另一块拼图。

于 2013-09-26T15:59:43.067 回答