I'm getting the following error after testing my Flash game's code:
ArgumentError: Error #1063: Argument count mismatch on RestartButton(). Expected 1, got 0. at flash.display::Sprite/constructChildren() at flash.display::Sprite() at flash.display::MovieClip() at Document()
RestartButton is the class of a MovieClip that has already been added to the stage.
Here is the section of my Document Class where the error is located in:
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();
publi开发者_JAVA百科c 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...
I would change the constructor of RestartButton to be parameter-less:
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
}
精彩评论