Can someone explain to me how I can set up an an application so that when a person types “3” in one text box and types “4” in another box, I can get another box to automatically give me what they add up to…
I understand if I have three text boxes… giving var names of “a”,“b”, and “c” I could do…
a=2*3
b=3+4
c=a+b
However that is me typing in the value of “a” and “b”.
How can I do it so another person can type in the two values so “C” can calculate the value?
As easy as one, two, three…
[AS]// define addition function
addition = function () {
// convert string to number
var a = a_txt.length ? parseInt(a_txt.text) : 0;
var b = b_txt.length ? parseInt(b_txt.text) : 0;
// do I need to explain this line? :****P
c_txt.text = a+b;
};
// create TextFields
this.createTextField(“a_txt”, 0, 0, 0, 80, 16);
this.createTextField(“b_txt”, 1, 100, 0, 80, 16);
this.createTextField(“c_txt”, 2, 200, 0, 80, 16);
// set text format
a_txt.setNewTextFormat(new TextFormat(“Verdana”, 10));
b_txt.setNewTextFormat(new TextFormat(“Verdana”, 10));
c_txt.setNewTextFormat(new TextFormat(“Verdana”, 10));
// set TextField type to input
a_txt.type = “input”;
b_txt.type = “input”;
// admit characters only from 0 to 9 and .
a_txt.restrict = “0-9.”;
b_txt.restrict = “0-9.”;
// show TextField border
a_txt.border = true;
b_txt.border = true;
// call function
a_txt.onChanged = addition;
b_txt.onChanged = addition;[/AS]
Of course, you can manually create the TextFields, I just didn’t want to attach a FLA. =)
That’s a really simple question, my dear friend… =)
I have no life.
Seriously now, I’m experimenting all day, or at least whenever I’m not working. Also, I’ve learned a lot from all of you and helping people.
There’s no secret, there are sources all over the web.