当我调试程序时,会出现错误。这是:
ArgumentError: Error #1063: Argument count mismatch on PlayerGril(). Expected 3, got 0.
at flash.display::Sprite/constructChildren()
at flash.display::Sprite()
at flash.display::MovieClip()
at MainGame()[E:\folder ni cj\DMTHESIS\dmgame\MainGame.as:52]
at Main/game()[E:\folder ni cj\DMTHESIS\dmgame\Main.as:188]
at Main/skip()[E:\folder ni cj\DMTHESIS\dmgame\Main.as:185]
以下是我的代码:
Main.as:
package {
import flash.display.*;
import flash.text.*;
import flash.events.Event;
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.desktop.NativeApplication;
import flash.events.TouchEvent;
import flash.display.Sprite;
import flash.display.Stage;
import flash.display.SimpleButton;
public class Main extends MovieClip {
public var playergril: PlayerGril;
private var stageRef:Stage;
private var thisThing:Object;
public var mainmenu: MainMenu = new MainMenu();
public var maingame: MainGame;
public var startopt: StartOpt = new StartOpt();
public var learnopt: LearnOpt = new LearnOpt();
public var newload: NewLoad = new NewLoad();
public var propocon: PropoCon = new PropoCon();
public var setcon: SetCon = new SetCon();
public var relationcon: RelationCon = new RelationCon();
public var scrollinstructwin: ScrollInstructWin = new ScrollInstructWin();
public var scrollstorywin: ScrollStoryWin = new ScrollStoryWin();
public function Main() {
addChild(mainmenu);
mainmenu.x = 350;
mainmenu.y = 290;
mainmenu.btnStart.addEventListener(MouseEvent.CLICK, start);
mainmenu.btnInstruct.addEventListener(MouseEvent.CLICK, instruct);
mainmenu.btnBye.addEventListener(MouseEvent.CLICK, bye);
}
public function start(event: MouseEvent): void {
removeChild(mainmenu);
addChild(startopt);
startopt.x = 350;
startopt.y = 290;
startopt.btnLearn.addEventListener(MouseEvent.CLICK, learn);
startopt.btnPlay.addEventListener(MouseEvent.CLICK, laro);
startopt.btnBack.addEventListener(MouseEvent.CLICK, back);
}
public function instruct(event: MouseEvent): void {
removeChild(mainmenu);
addChild(scrollinstructwin);
scrollinstructwin.x = 36.20;
scrollinstructwin.y = 21.50;
var max_Y: Number = 0;
var min_Y: Number = Math.min(0, stage.stageHeight - scrollinstructwin.scrollinstruct.height);
var startY: Number;
var startMouseY: Number;
addChild(scrollinstructwin.scrollinstruct);
addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event: MouseEvent): void {
startY = scrollinstructwin.scrollinstruct.y;
startMouseY = mouseY;
stage.addEventListener(MouseEvent.MOUSE_MOVE, stagemouseMoveHandler, false, 0, true);
stage.addEventListener(MouseEvent.MOUSE_UP, stagemouseUpHandler, false, 0, true);
}
function stagemouseMoveHandler(event: MouseEvent): void {
var offset_Y: Number = mouseY - startMouseY;
scrollinstructwin.scrollinstruct.y = Math.max(Math.min(max_Y, startY + offset_Y), min_Y);
}
function stagemouseUpHandler(event: MouseEvent): void {
stage.removeEventListener(MouseEvent.MOUSE_MOVE, stagemouseMoveHandler);
stage.removeEventListener(MouseEvent.MOUSE_UP, stagemouseUpHandler);
}
scrollinstructwin.btnGi.addEventListener(MouseEvent.CLICK, gi);
}
public function bye(event: MouseEvent): void {
NativeApplication.nativeApplication.exit(0);
}
public function gi(event: MouseEvent): void {
removeChild(scrollinstructwin);
addChild(mainmenu);
mainmenu.x = 350;
mainmenu.y = 290;
}
public function back(event: MouseEvent): void {
removeChild(startopt);
addChild(mainmenu);
mainmenu.x = 350;
mainmenu.y = 290;
}
public function learn(event: MouseEvent): void {
removeChild(startopt);
addChild(learnopt);
learnopt.x = 350;
learnopt.y = 290;
learnopt.btnPropo.addEventListener(MouseEvent.CLICK, propo);
learnopt.btnSets.addEventListener(MouseEvent.CLICK, sets);
learnopt.btnRelations.addEventListener(MouseEvent.CLICK, relations);
learnopt.btnBack3.addEventListener(MouseEvent.CLICK, backo);
}
public function laro(event: MouseEvent): void {
removeChild(startopt);
addChild(newload);
newload.x = 350;
newload.y = 290;
newload.btnNew.addEventListener(MouseEvent.CLICK, neww);
newload.btnBack2.addEventListener(MouseEvent.CLICK, backu);
}
public function backo(event: MouseEvent): void {
removeChild(learnopt);
addChild(startopt);
startopt.x = 350;
startopt.y = 290;
}
public function neww(event: MouseEvent): void {
removeChild(newload);
addChild(scrollstorywin);
scrollstorywin.x = 51.15;
scrollstorywin.y = 30.05;
var maxY: Number = 0;
var minY: Number = Math.min(0, stage.stageHeight - scrollstorywin.scrollcontent.height);
//var minY_: Number = Math.min(0, stage.stageHeight - scrollstorywin.scrollcontent2.height);
var _startY: Number;
var _startMouseY: Number;
addChild(scrollstorywin.scrollcontent);
addEventListener(MouseEvent.MOUSE_DOWN, mouseoDownHandler);
function mouseoDownHandler(event: MouseEvent): void {
_startY = scrollstorywin.scrollcontent.y;
_startMouseY = mouseY;
/*_startY = scrollstorywin.scrollContent2.y;
_startMouseY = mouseY;*/
stage.addEventListener(MouseEvent.MOUSE_MOVE, stage_mouseMoveHandler, false, 0, true);
stage.addEventListener(MouseEvent.MOUSE_UP, stage_mouseUpHandler, false, 0, true);
}
function stage_mouseMoveHandler(event: MouseEvent): void {
var offsetY: Number = mouseY - _startMouseY;
scrollstorywin.scrollcontent.y = Math.max(Math.min(maxY, _startY + offsetY), minY);
//scrollstorywin.scrollContent2.y = Math.max(Math.min(maxY, _startY + offsetY), minY_);
}
function stage_mouseUpHandler(event: MouseEvent): void {
stage.removeEventListener(MouseEvent.MOUSE_MOVE, stage_mouseMoveHandler);
stage.removeEventListener(MouseEvent.MOUSE_UP, stage_mouseUpHandler);
}
scrollstorywin.btnCho.addEventListener(MouseEvent.CLICK, nw);
scrollstorywin.btnSkip.addEventListener(MouseEvent.CLICK, skip);
scrollstorywin.scrollcontent.btnCC.addEventListener(MouseEvent.CLICK, cc);
scrollstorywin.scrollcontent.btnAA.addEventListener(MouseEvent.CLICK, aa);
//scrollstorywin.scrollcontent2.btnSaa.addEventListener(MouseEvent.CLICK, saa);
}
public function nw(event: MouseEvent): void {
removeChild(scrollstorywin);
addChild(newload);
mainmenu.x = 350;
mainmenu.y = 290;
}
private function skip(event: MouseEvent): void {
removeChild(scrollstorywin);
game();
}
private function game(){
maingame = new MainGame(stageRef, thisThing);
thisThing.visible = true;
//addChild(maingame);
maingame.x = 415.00;
maingame.y = 228.00;
maingame.gotoAndStop(1);
}
public function cc(event: MouseEvent): void {
removeChild(scrollstorywin.scrollcontent);
scrollstorywin.scrollcontent.gotoAndStop(2);
}
public function aa(event: MouseEvent): void {
removeChild(scrollstorywin);
addChild(newload);
newload.x = 350;
newload.y = 290;
}
/*public function saa(event: MouseEvent): void {
removeChild(scrollstorywin.scrollcontent2);
addChild(maingame);
}*/
public function backu(event: MouseEvent): void {
removeChild(newload);
addChild(startopt);
startopt.x = 350;
startopt.y = 290;
}
public function propo(event: MouseEvent): void {
removeChild(learnopt);
propocon.gotoAndStop(1);
addChild(propocon);
propocon.x = 414.80;
propocon.y = 218.60;
//propocon.btnBtm.addEventListener(MouseEvent.CLICK, popo);
propocon.btnExit.addEventListener(MouseEvent.CLICK, byeol);
//propocon.btnQt.addEventListener(MouseEvent.CLICK, qtu);
}
/*public function popo(event: MouseEvent): void {
removeChild(propocon);
addChild(learnopt);
learnopt.x = 350;
learnopt.y = 290;
}*/
public function byeol(event: MouseEvent): void {
removeChild(propocon);
addChild(learnopt);
learnopt.x = 350;
learnopt.y = 290;
}
/*public function qtu(event: MouseEvent): void {
removeChild(propocon);
addChild(mainmenu);
mainmenu.x = 350;
mainmenu.y = 290;
}*/
public function sets(event: MouseEvent): void {
removeChild(learnopt);
setcon.gotoAndStop(1);
addChild(setcon);
setcon.x = 412.45;
setcon.y = 225.00;
setcon.btnBai2.addEventListener(MouseEvent.CLICK, byeo);
//setcon.btnBtm2.addEventListener(MouseEvent.CLICK, pop);
//setcon.btnQt2.addEventListener(MouseEvent.CLICK, qti);
}
public function byeo(event: MouseEvent): void {
removeChild(setcon);
addChild(learnopt);
learnopt.x = 350;
learnopt.y = 290;
}
/*public function pop(event: MouseEvent): void {
removeChild(setcon);
addChild(learnopt);
learnopt.x = 350;
learnopt.y = 290;
}
public function qti(event: MouseEvent): void {
removeChild(setcon);
addChild(mainmenu);
mainmenu.x = 350;
mainmenu.y = 290;
}*/
public function relations(event: MouseEvent): void {
removeChild(learnopt);
relationcon.gotoAndStop(1);
addChild(relationcon);
relationcon.x = 400.00;
relationcon.y = 225.00;
relationcon.btnBai3.addEventListener(MouseEvent.CLICK, byel);
//relationcon.btnBtm3.addEventListener(MouseEvent.CLICK, poup);
//relationcon.btnQt3.addEventListener(MouseEvent.CLICK, qtui);
}
public function byel(event: MouseEvent): void {
removeChild(relationcon);
addChild(learnopt);
learnopt.x = 350;
learnopt.y = 290;
}
/*public function poup(event: MouseEvent): void {
removeChild(relationcon);
addChild(learnopt);
learnopt.x = 350;
learnopt.y = 290;
}
public function qtui(event: MouseEvent): void {
removeChild(relationcon);
addChild(mainmenu);
mainmenu.x = 350;
mainmenu.y = 290;
}*/
}
}
根据错误,以下是此AS文件中受影响的代码:
第185行:game();
第188行:maingame = new MainGame(stageRef, thisThing);
MainGame.as(来自movieclip符号):
package {
import flash.display.*;
import flash.text.*;
import flash.display.MovieClip;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.display.DisplayObject;
import flash.geom.Point;
import flash.display.Stage;
import flash.display.Sprite;
public class MainGame extends MovieClip {
private var main: Main;
public var playergril: PlayerGril;
public var key: Key = new Key();
public var door: Door = new Door();
public var pausewin: PauseWin = new PauseWin();
public var corekwin: CorekWin = new CorekWin();
public var maliwin: MaliWin = new MaliWin();
public var gameoverwin: GameOverWin = new GameOverWin();
public var scorerr: Scorer = new Scorer();
public var timerr: Timerr = new Timerr();
public var lives: Lives = new Lives();
public var room: Room = new Room();
public var room2: Room2 = new Room2();
public var room3: Room3 = new Room3();
public var room4: Room4 = new Room4();
public var room5: Room5 = new Room5();
public var quizquest: QuizQuest = new QuizQuest();
public var quizquest2: QuizQuest2 = new QuizQuest2();
public var quizquest3: QuizQuest3 = new QuizQuest3();
public var quizquest4: QuizQuest4 = new QuizQuest4();
public var quizquest5: QuizQuest5 = new QuizQuest5();
public var gamestage: int = 0;
public var buhay: int = 0;
public var iskoru: int = 0;
private var stageRef:Stage;
private var thisThing:Object;
private var walkRate:Number;
private var targetBuffer:Number;
/*public var v: Number = 5;
public var dir: int = 0;
public var clickPoint: Point = new Point();
public var angle: Number;
public var goX: Number;
public var goY: Number;*/
public function MainGame(stageRef:Stage, thisThing:Object) {
this.stageRef = stageRef;
this.thisThing = thisThing;
this.scorerr.visible = false;
this.timerr.visible = false;
this.pausewin.visible = false;
this.quizquest.visible = false;
this.quizquest2.visible = false;
this.quizquest3.visible = false;
this.quizquest4.visible = false;
this.quizquest5.visible = false;
startgame();
}
private function startgame() {
playergril = new PlayerGril(stageRef, walkRate, targetBuffer);
for (var i = 0; i > 5; i++) {
buhay = 3;
this.lives.txtLives.text = buhay.toString();
if (gamestage == 1) {
this.room.x = -15.00;
this.room.y = -1.00;
this.room.visible = true;
//walk();
addChild(key);
if (key.hitTestObject(playergril)) {
this.gotoAndStop(2);
i++;
quiztime();
}
} else if (gamestage == 2) {
this.room2.x = -15.85;
this.room2.y = -0.90;
this.room2.visible = true;
//walk();
addChild(key);
if (key.hitTestObject(playergril)) {
this.gotoAndStop(4);
i++;
quiztime2();
}
} else if (gamestage == 3) {
this.room3.x = -15.80;
this.room3.y = -1.00;
this.room3.visible = true;
//walk();
addChild(key);
if (key.hitTestObject(playergril)) {
this.gotoAndStop(6);
i++;
quiztime3();
}
} else if (gamestage == 4) {
this.room4.x = -15.40;
this.room4.y = -2.05;
this.room4.visible = true;
//walk();
addChild(key);
if (key.hitTestObject(playergril)) {
this.gotoAndStop(8);
i++;
quiztime4();
}
} else if (gamestage == 5) {
this.room5.x = -15.80;
this.room5.y = -0.95;
this.room5.visible = true;
//walk();
addChild(key);
if (key.hitTestObject(playergril)) {
this.gotoAndStop(10);
i++;
quiztime5();
}
}
this.btnPause.addEventListener(MouseEvent.CLICK, oop);
}
function oop(event: MouseEvent): void {
stage.frameRate = 0;
this.gotoAndStop(11);
this.pausewin.btnResume.addEventListener(MouseEvent.CLICK, op);
}
function op(event: MouseEvent): void {
stage.frameRate = 24;
}
}
/*public function walk() {
this.btnForward.addEventListener(MouseEvent.CLICK, myClickReaction);
function myClickReaction(e: MouseEvent): void {
var target = e.target;
if (target == this.btnForward) {
goX = mouseX;
goY = mouseY;
}
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
}
function onEnterFrame(event: Event): void {
var xDistance: Number = clickPoint.x - playergril.x;
var yDistance: Number = clickPoint.y - playergril.y;
var angle: Number = Math.atan2(yDistance, xDistance);
playergril.x += v * Math.cos(angle);
playergril.y += v * Math.sin(angle);
playergril.gotoAndPlay(1);
if (xDistance <= 0) {
trace("works");
playergril.gotoAndPlay(8);
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
}
}*/
public function quiztime() {
this.quizquest.visible = true;
this.scorerr.visible = true;
this.timerr.visible = true;
this.quizquest.ans11.buttonMode = true;
this.quizquest.ans12.buttonMode = true;
this.quizquest.ans13.buttonMode = true;
this.quizquest.ans11.addEventListener(MouseEvent.CLICK, buttones1);
this.quizquest.ans12.addEventListener(MouseEvent.CLICK, buttones2);
this.quizquest.ans13.addEventListener(MouseEvent.CLICK, buttones3);
function buttones1(eventObject: MouseEvent): void {
this.gotoAndStop(12);
iskoru += 1;
this.scorerr.txtSkor.text = iskoru.toString();
}
function buttones2(eventObject: MouseEvent): void {
this.gotoAndStop(13);
buhay -= 1;
this.lives.txtLives.text = buhay.toString();
}
function buttones3(eventObject: MouseEvent): void {
this.gotoAndStop(13);
buhay -= 1;
this.lives.txtLives.text = buhay.toString();
}
}
public function quiztime2() {
this.quizquest2.visible = true;
this.scorerr.visible = true;
this.timerr.visible = true;
this.quizquest2.ans21.buttonMode = true;
this.quizquest2.ans22.buttonMode = true;
this.quizquest2.ans23.buttonMode = true;
this.quizquest2.ans21.addEventListener(MouseEvent.CLICK, buttones4);
this.quizquest2.ans22.addEventListener(MouseEvent.CLICK, buttones5);
this.quizquest2.ans23.addEventListener(MouseEvent.CLICK, buttones6);
function buttones4(eventObject: MouseEvent): void {
this.gotoAndStop(13);
buhay -= 1;
this.lives.txtLives.text = buhay.toString();
}
function buttones5(eventObject: MouseEvent): void {
this.gotoAndStop(13);
buhay -= 1;
this.lives.txtLives.text = buhay.toString();
}
function buttones6(eventObject: MouseEvent): void {
this.gotoAndStop(12);
iskoru += 1;
this.scorerr.txtSkor.text = iskoru.toString();
}
}
public function quiztime3() {
this.quizquest3.visible = true;
this.scorerr.visible = true;
this.timerr.visible = true;
this.quizquest3.ans31.buttonMode = true;
this.quizquest3.ans32.buttonMode = true;
this.quizquest3.ans33.buttonMode = true;
this.quizquest3.ans31.addEventListener(MouseEvent.CLICK, buttones7);
this.quizquest3.ans32.addEventListener(MouseEvent.CLICK, buttones8);
this.quizquest3.ans33.addEventListener(MouseEvent.CLICK, buttones9);
function buttones7(eventObject: MouseEvent): void {
this.gotoAndStop(13);
buhay -= 1;
this.lives.txtLives.text = buhay.toString();
}
function buttones8(eventObject: MouseEvent): void {
this.gotoAndStop(13);
buhay -= 1;
this.lives.txtLives.text = buhay.toString();
}
function buttones9(eventObject: MouseEvent): void {
this.gotoAndStop(12);
iskoru += 1;
this.scorerr.txtSkor.text = iskoru.toString();
}
}
public function quiztime4() {
this.quizquest4.visible = true;
this.scorerr.visible = true;
this.timerr.visible = true;
this.quizquest4.ans41.buttonMode = true;
this.quizquest4.ans42.buttonMode = true;
this.quizquest4.ans43.buttonMode = true;
this.quizquest4.ans41.addEventListener(MouseEvent.CLICK, buttones10);
this.quizquest4.ans42.addEventListener(MouseEvent.CLICK, buttones11);
this.quizquest4.ans43.addEventListener(MouseEvent.CLICK, buttones12);
function buttones10(eventObject: MouseEvent): void {
this.gotoAndStop(13);
buhay -= 1;
lives.txtLives.text = buhay.toString();
}
function buttones11(eventObject: MouseEvent): void {
this.gotoAndStop(13);
buhay -= 1;
this.lives.txtLives.text = buhay.toString();
}
function buttones12(eventObject: MouseEvent): void {
this.gotoAndStop(12);
iskoru += 1;
this.scorerr.txtSkor.text = iskoru.toString();
}
}
public function quiztime5() {
this.quizquest5.visible = true;
this.scorerr.visible = true;
this.timerr.visible = true;
this.quizquest5.ans51.buttonMode = true;
this.quizquest5.ans52.buttonMode = true;
this.quizquest5.ans53.buttonMode = true;
this.quizquest5.ans51.addEventListener(MouseEvent.CLICK, buttones13);
this.quizquest5.ans52.addEventListener(MouseEvent.CLICK, buttones14);
this.quizquest5.ans53.addEventListener(MouseEvent.CLICK, buttones15);
function buttones13(eventObject: MouseEvent): void {
this.gotoAndStop(12);
iskoru += 1;
this.scorerr.txtSkor.text = iskoru.toString();
}
function buttones14(eventObject: MouseEvent): void {
this.gotoAndStop(13);
buhay -= 1;
this.lives.txtLives.text = buhay.toString();
}
function buttones15(eventObject: MouseEvent): void {
this.gotoAndStop(13);
buhay -= 1;
this.lives.txtLives.text = buhay.toString();
}
if (buhay == 0) {
this.gotoAndStop(14);
this.gameoverwin.btnTry.addEventListener(MouseEvent.CLICK, dasi);
}
function dasi(event: MouseEvent): void {
this.gameoverwin.visible = false;
startgame();
this.btnPause.addEventListener(MouseEvent.CLICK, tgil);
}
function tgil(event: MouseEvent): void {
this.gotoAndStop(11);
}
}
}
}
第52行受影响的代码:public function MainGame(stageRef:Stage, thisThing:Object) {
我无法从中找到错误的代码行。我试图修复错误但仍然出现错误。我的代码有什么问题吗?我该如何解决这些错误?任何帮助,将不胜感激。感谢。
答案 0 :(得分:0)
如何解决这些错误?任何帮助将不胜感激
使用trace
仔细检查可能导致问题的任何变量。
例如,在 MainGame.as 中,关于private function startgame()
,在声明= new PlayerGril
代码之前,为什么不检查输入参数是否实际上有效强>
trace("check stageRef : " + stageRef); //if null = wont work
trace("check walkRate : " + walkRate); //if NaN = wont work
trace("check targetBuffer : " + targetBuffer); //if NaN = wont work
playergril = new PlayerGril(stageRef, walkRate, targetBuffer); //are all 3 parameters ok?
另请注意,在制作public class MainGame
时,您确实创建了stageRef
,walkRate
和targetBuffer
之类的变量,这很好,但是从未给出值那些变量。
我们认为walkRate
是一个数字但无处在运行 调用function startgame()
之前的任何代码中你是否确切地告诉编译器多少是walkRate
!!
您认为:playergril = new PlayerGril(stageRef, walkRate, targetBuffer);
编译器看到:playergril = new PlayerGril(nothing, nothing, nothing);