Copy link to clipboard
Copied
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!!!
1 Correct answer
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++;
}
Copy link to clipboard
Copied
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++;
}
Copy link to clipboard
Copied
Well, where is the number of clicks supposed to show up?
Copy link to clipboard
Copied
if you have a dynamic text, give it the instance name _clickTxt
covert clickCount in to a string
_clickTxt.text = clickCountString;
Copy link to clipboard
Copied
Ok, so here is the code I have:
- stop();
- var clickCount:int = 0;
- btn.addEventListener(MouseEvent.CLICK, addClick);
- function addClick(event:MouseEvent):void {
- clickCount++;
- }
- _clickTxt.text = " SCORE:"+clickCount.toString();
When i run the program, I see the text box says "SCORE: 0" and when I click the button nothing happens. Is there some sort of way I need to update the string after every click?
Copy link to clipboard
Copied
Yes, each time you increment the value you update the textfield too...
- function addClick(event:MouseEvent):void {
- clickCount++;
- _clickTxt.text = " SCORE:"+clickCount.toString();
- }

