I’m using the following script to try to add together a set of scores as soon as they change in input text fields.
var score1:Number = 2;
var score2:Number = 3;
var score3:Number = 4;
var score4:Number = 5;
var score5:Number = 6;
var score6:Number = 2;
var score7:Number = 1;
var total:Number = score1 + score2 + score3 + score4 + score5 + score6 + score7;
score1_txt.onChanged = function() {
if (score1_txt.text > 5) {
trace("I'm sorry, you can only enter a number between 1 and 5");
}
total_txt.text = total;
}
The value won’t update. If I put total_txt.text = score1 + total, it just concatenates the value of score1 to the end of total.
I read somewhere that adding an eventListener would help, but in this case there’s only 1 textField called total that needs to be updated. What can I do?