Math works the same way in AS3 as it does in AS2. Though, I would use a separate variable to do the counting, and let counter.text reflect it. on(release) however, works differently...
Code:
var count:uint = 0;
myBtn.addEventListener(MouseEvent.CLICK, addCount);
counter.text = '0';
function addCount(event:Event):void
{
count++;
counter.text = count.toString();
}
this assumes that you have a textfield name "counter" and a button named "myBtn" on the stage.
So, if I had 5 buttons on the stage and I wanted to use the same dynamic text to record the number of overall hits from all buttons, I can use a similar code for each button?
I tried this, but it just shows up the individual counts for each button....
var count:uint = 0;
counter.text = '0';
myBtn1.addEventListener(MouseEvent.CLICK, btnClick1);
myBtn2.addEventListener(MouseEvent.CLICK, btnClick2);
function btnClick1(event:MouseEvent):void
{
// add code for your button here
addCount();
}
function btnClick2(event:MouseEvent):void
{
// add code for your other button here
addCount();
}
function addCount():void
{
count++;
counter.text = count.toString();
}
Hi, i have tried this code with a few buttons with different input text boxes, but when i click on different buttons, it keeps adding or subtracting the amount of clicks in the other text boxes? Any help would be grateful. Cheers
Hi, i have tried this code with a few buttons with different input text boxes, but when i click on different buttons, it keeps adding or subtracting the amount of clicks in the other text boxes? Any help would be grateful. Cheers
Hi, im not sure about this cause i came also to check if there was any code to do such counting ....anyway...did you tried to change the instance name of each text box into a diferent name? ... im also further to test this code in a project...