我一直在编码一个非常基本的游戏的开始,我碰到了一堵墙。当我编译我的代码,游戏运行,但吐出运行时错误:Flash游戏错误#1063
ArgumentError: Error #1063: Argument count mismatch on block(). Expected 2, got 0.
at flash.display:: Sprite/constructChildren()
at flash display::Sprite()
at flash.display::MovieClip()
at AvoiderGame().
这里是我的文档类名为AvoiderGame
:
package
{
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
public class AvoiderGame extends MovieClip
{
public var avatar1:avatar;
public var gameTimer:Timer;
public var army:Array;
public function AvoiderGame()
{
army=new Array();
var newblock= new block(100,-15);
army.push(newblock);
addChild(newblock);
avatar1=new avatar();
addChild (avatar1);
avatar1.x=mouseX;
avatar1.y=mouseY;
gameTimer=new Timer(25);
gameTimer.addEventListener(TimerEvent.TIMER, onTick);
gameTimer.start();
}
public function onTick(timerEvent:TimerEvent):void
{
if (Math.random() < 0.1)
{
var randomX:Number = Math.random() * 400;
var newblock:block = new block(randomX, -15);
army.push(newblock);
addChild(newblock);
}
avatar1.x = mouseX;
avatar1.y = mouseY;
for each (var block1:block in army)
{
block1.moveDownaBit();
if (avatar1.hitTestObject(block1))
{
gameTimer.stop();
}
}
}
}
}
最后,这里是我block
类里面好像有构造函数导致错误。
package
{
import flash.display.MovieClip;
public class block extends MovieClip
{
public var block1:block;
public function block(startX:Number, startY:Number)
{
x=startX;
y=startY;
}
public function moveDownaBit():void
{
y=y+3;
}
}
}
所有我试图去工作是一系列的敌人在舞台上随机产卵和落下没有头像图标击中它的。我会很感激任何帮助,我可以收到很大。
嗨,我已经更新了你的问题和@DavidMear提供使用单词'block'答案。 – Marty