大家好,我是编程新手,我正在关注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;
}
}
}
注意:我完成了教程