在测试我的Flash游戏代码后,我收到以下错误:
ArgumentError:错误#1063:RestartButton()上的参数计数不匹配。预计1,得0。 在flash.display :: Sprite / constructChildren() 在flash.display :: Sprite() 在flash.display :: MovieClip() 在Document()
RestartButton是已添加到舞台的MovieClip的类。
以下是我的文档类的部分,其中错误位于:
package
{
import flash.events.*;
import flash.display.*;
import flash.geom.Point;
import RestartButton;
import Level_2;
public class Document extends MovieClip
{
public var leftKeyDown:Boolean = false;
public var rightKeyDown:Boolean = false;
public var upKeyDown:Boolean = false;
public var downKeyDown:Boolean = false;
public var onGround:Boolean = true;
public var xSpeed:Number = 0;
public var ySpeed:Number = 0;
public var mainSpeed:Number = 3.75;
public var frictionPower:Number = 0.9;
public var jumpPower:Number = 13;
public var gravityPower:Number = 0.5;
public var terminalVelocity:Number = 75;
public var levelNumber:int = 1;
public var levelChange:Object;
public var levelArray:Array = new Array();
public var collisionArray:Array = new Array();
public var deathAreaArray:Array = new Array();
public var goalAreaArray:Array = new Array();
public var goalHitAreaArray:Array = new Array();
public var restartButton:RestartButton;
public var level_2:Level_2;
public function Document()
{
addEventListener(Event.ADDED_TO_STAGE, init);
restartButton = new RestartButton(this);
level_2 = new Level_2();
// constructor code
}
public function init(event:Event)
{
stage.addEventListener(KeyboardEvent.KEY_DOWN,checkKeysDown);
stage.addEventListener(KeyboardEvent.KEY_UP,checkKeysUp);
stage.addEventListener(Event.ENTER_FRAME,levelHandler);
stage.addEventListener(Event.ENTER_FRAME,hitTest);
stage.addEventListener(Event.ENTER_FRAME,vCamMovement);
stage.addEventListener(Event.ENTER_FRAME,Main);
this.levelChange = this.level_1;
}
//...Section Removed...
答案 0 :(得分:0)
我会将RestartButton的构造函数更改为无参数:
public class RestartButton extends MovieClip
{
public var document:Document;
public function RestartButton()
{
}
...
}
... then in your Document class
public function Document()
{
addEventListener(Event.ADDED_TO_STAGE, init);
restartButton = new RestartButton();
restartButton.document = this;
level_2 = new Level_2();
// constructor code
}