Adding a limit to how often you can press a button in as3

I'm coding a game for Android on Flash using AS3. My problem is that when I shoot a rocket or bullet at an enemy the user can repeatedly press the virtual button (on screen), this defeats the object of the game. Is there any way to limit how often a user can press this button so it can be pressed every half second or so? Many Thanks. (will provide code upon request if needed)

Upvotes: 0

Views: 56

Answers (1)

null
null

Reputation: 5255

In the event handler that handles the button press, remove the listener.

This alone would disable the button.

Additionally, start a Timer. Upon completion of the timer, re-add the listener for the button press, which allows pressing the button again, but only after the timer completed.

Upvotes: 0

Related Questions