Add 3 values from input text boxes, display total

Hey people,

Just a quick query here, I want to be able to add the sum of 3 input text boxes and have the total be displayed in another text box.

I figure I set a variable and do something along the lines of:

Number = "_root.input1 + _root.input2 + _root.input3";

Or do I have to do this another way?

Also where should I put the code? In a button? Or can I stick it in the frame to save complications of users clicking on a button.

Thanks

G

you can use the onChanged event handler so you don’t need to click any button.

that would be something like this:

input1.onChanged = input2.onChanged=input3.onChanged=function() {
	output.text = Number(input1.text)+Number(input2.text)+Number(input3.text);
};

hope it helps… =)

Thanks, I have got a bit further now, the main problem im having though is getting the values to add properlly, currently I have:

on (release) {
output = _root.output;
input1 = _root.input1;
input2 = _root.input2;
output = input1 + input2;
}

But instead of adding 1 + 1 to make 2… it just makes it 11

This is obviously a formating thing or something to do with the value being boolean, I can’t remember. If you can shed some light on this so the values are actually adding correctly I would be grateful.

that’s why i used Number(whatever). flash interprets those values as strings. :-\

Yeah got that working thanks! But I can’t get decimal points now…

Say 15 divided by 2 = 7.5 I just get 75 :slight_smile:

on (release) {
output = _root.output;
output2 = _root.output2;
input1 = _root.input1;
input2 = _root.input2;
input3 = _root.input3;
output = (Number(input1) + Number(input2));
output2 = (Number(output) * Number(input3));
}

I eventually want to have an average and a percentage in 2 diff boxes.

Thanks!

S’ok got it working i hadnt allowed a . and a - in the dynamic text fields :slight_smile: