1136:参数数量不正确。预期为0. on var ourShip:ship = new ship(stage);

时间:2013-09-26 15:54:04

标签: actionscript-3 flash

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

的教程

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

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;
        }

    }

}

另外要告诉我改变了

的senocular包
package come.asgamer.....{}

package utils{}

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

我认为麻烦与此相关的问题

顺便说一句,如果我改变

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;
        }
    }
}

注意:我完成了教程

1 个答案:

答案 0 :(得分:0)

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

您可能正在使用与您认为正在使用的课程不同的课程。他们提供的课程是Ship,而不是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不起作用,那么你正朝着正确的方向前进,但可能还有另一个问题。