lock
lock

Reputation: 13

how can i fix this, "ArgumentError: Error #1063: Argument count mismatch"

Iv'e been working on this code and i don't know what to do. This is my code that I'm trying to fix:

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();
}
}

What its suppose to do is when I hold down spacebar, it will keep shooting until i let go. But i keep getting:

"ArgumentError: Error #1063: Argument count mismatch on hell_fla::MainTimeline/shootBullet(). Expected 0, got 1.

ArgumentError: Error #1063: Argument count mismatch on hell_fla::MainTimeline/stoptimer(). Expected 0, got 1."

Can someone help me? Thanks.

Upvotes: 1

Views: 494

Answers (1)

VC.One
VC.One

Reputation: 15871

"What it's suppose to do is when I hold down spacebar, it will keep shooting until I let go..."

Better use an Enter_frame event instead of Timer event to achieve such movement.

Try something like this:

//#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);
    }
}

Upvotes: 1

Related Questions