Skip to main content
May 11, 2014
Answered

Reducing bullets every single time mouse is clocked

  • May 11, 2014
  • 1 reply
  • 284 views

How do you make the bullets reduce by one everytime u click one time.

This is what i have tried so far

function duckGame(evt:MouseEvent):void

{

bullet = 20;

  bulletsTxt.text = bullet.toString();

}

function setBullet():void

  {

  bullet = bullet - 1;

  bulletsTxt.text = bullet.toString();

  }

If possible can u give me the code as i am not very sure how to do it.

This topic has been closed for replies.
Correct answer kglad

that should work (thought there's a commonly used shorcut you can use) but you need to call setBullet when you detect a mouse click

stage.addEventListener(MouseEvent.CLICK,setBullet);

function duckGame(evt:MouseEvent):void

{

bullet = 20;

  bulletsTxt.text = bullet.toString();

}

function setBullet():void

  {

  //bullet = bullet - 1; //<-this will work well but commonly:

bullet--;

  bulletsTxt.text = bullet.toString();

  }

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
May 11, 2014

that should work (thought there's a commonly used shorcut you can use) but you need to call setBullet when you detect a mouse click

stage.addEventListener(MouseEvent.CLICK,setBullet);

function duckGame(evt:MouseEvent):void

{

bullet = 20;

  bulletsTxt.text = bullet.toString();

}

function setBullet():void

  {

  //bullet = bullet - 1; //<-this will work well but commonly:

bullet--;

  bulletsTxt.text = bullet.toString();

  }

May 12, 2014

thx bro it worked

kglad
Community Expert
Community Expert
May 12, 2014

you're welcome.