我该如何解决这个问题," ArgumentError:错误#1063:参数计数不匹配"

时间:2017-06-10 06:38:24

标签: actionscript-3 flash

我一直在研究这个代码而且我不知道该怎么做。 这是我试图解决的代码:

stage.addEventListener(KeyboardEvent.KEY_DOWN, detectKey);

 function detectKey(e:KeyboardEvent):void {
 // space: shoot
 if (e.keyCode == 32) {
    shootBullet();
 }
}



stage.addEventListener(KeyboardEvent.KEY_DOWN, shootBullet);

function shootBullet():void{
 var bulletSpeed:Number = 80;
 var bullet:Rapid = new Rapid();
 stage.addChild(bullet);
 bullet.x = mini.x
 bullet.y = mini.y - 20
 var gameplay:Timer = new Timer(200);
 gameplay.start();
 gameplay.addEventListener(TimerEvent.TIMER, moveBullet);
 function moveBullet(e:TimerEvent):void{
     bullet.y -= bulletSpeed;
    if(bullet.y > stage.stageHeight + bullet.height){
         stage.removeChild(bullet);
 }
 }
}

stage.addEventListener(KeyboardEvent.KEY_UP, stoptimer);

function stoptimer():void{

var end:Timer = new Timer(500);
end.stop();
end.removeEventListener(TimerEvent.TIMER, remove);
function remove(e:TimerEvent):void {
    shootBullet();
}
}

它想要做的是当我按住空格键时,它会一直拍摄直到我松开。但我一直在接受:

  

" ArgumentError:错误#1063:参数计数不匹配   hell_fla :: MainTimeline / shootBullet()。预计为0,得到1。

     

ArgumentError:错误#1063:参数计数不匹配   hell_fla :: MainTimeline / stoptimer()。预期为0,得到1。"

有人能帮助我吗?感谢。

1 个答案:

答案 0 :(得分:1)

  

"它想要做的是当我按住空格键时,它会保留   拍摄直到我放手......"

最好使用Enter_frame事件代替Timer事件来实现此类移动。

尝试这样的事情:

//#1 Add Vars

var bulletSpeed:Number = 80;
var bullet:Rapid;
var gameplay:Timer;


//#2 Add Listeners

//stage.addEventListener(KeyboardEvent.KEY_DOWN, shootBullet); //causes error
stage.addEventListener(KeyboardEvent.KEY_DOWN, detectKey); //better way


//#3 Add Functions

function detectKey(e:KeyboardEvent):void 
{
    // space: shoot
    if (e.keyCode == 32) { shootBullet(); }
}

function shootBullet():void
{
    bullet = new Rapid();
    stage.addChild(bullet);
    bullet.x = mini.x;
    bullet.y = mini.y - 20;

    // instead of gameplay timer setting up, just use :
    // each unique NEW bullet will follow instruction in "moveBullet"
    bullet.addEventListener(Event.ENTER_FRAME, moveBullet);

}

function moveBullet(evt:Event):void
{
    evt.currentTarget.y -= bulletSpeed;
    if(evt.currentTarget.y > stage.stageHeight + evt.currentTarget.height)
    {
         stage.removeChild(evt.currentTarget as DisplayObject);
    }
}