使用Flash Professional CS5,我正在尝试在我的脚本中添加子对象。我想在创建时将创建子对象的类作为参数。问题是当我尝试测试项目时,我收到一条错误,指出Incorrect number of arguments. 0 expected.
我的MainClass.as
:
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
public class MainClass extends MovieClip {
var menuClass:MenuClass;
var gameClass:GameClass;
var highClass:HighscoreClass;
public function Main() {
this.StartOfProject();
}
public function StartOfProject() {
menuClass = new MenuClass(this);
this.addChild(menuClass);
highClass = new HighscoreClass();
}
我的MenuClass.as
:
package {
public class MenuClass extends MovieClip {
var mainClass:MainClass;
public function Menu(mainClass:MainClass) {
this.mainClass = mainClass;
...
}
我做错了什么?
答案 0 :(得分:1)
您错误地命名了MenuClass的构造函数。它应该是" MenuClass"不是"菜单"
答案 1 :(得分:1)
改变:
public function Main() {
this.StartOfProject();
}
为:
public function MainClass() {
this.StartOfProject();
}
和:
public function Menu(mainClass:MainClass)
至:public function MenuClass (mainClass:MainClass)
并查看这是否已解决您的问题