Skip to main content
Participant
April 29, 2014
Answered

Actionscript 3 Button that counts clicks

  • April 29, 2014
  • 1 reply
  • 4629 views

I know I am a total noob to flash, but is there a way to make a button that has a number that goes up each time you click it in actionscript 3? If so please HELP ME!!!

This topic has been closed for replies.
Correct answer Ned Murphy

If you created a button and assigned it an instance name "btn", the following code will do what you ask...

var clickCount:int = 0;

btn.addEventListener(MouseEvent.CLICK, addClick);

function addClick(evt:MouseEvent):void {

      clickCount++;

}

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
April 29, 2014

If you created a button and assigned it an instance name "btn", the following code will do what you ask...

var clickCount:int = 0;

btn.addEventListener(MouseEvent.CLICK, addClick);

function addClick(evt:MouseEvent):void {

      clickCount++;

}

PcowAuthor
Participant
April 29, 2014

Well, where is the number of clicks supposed to show up?

Participating Frequently
April 29, 2014

if you have a dynamic text, give it the instance name _clickTxt

covert clickCount in to a string

_clickTxt.text = clickCountString;