Variables and textfields

Ok I´m a moron, and I can´t figure this out.

Hoping for some help.

Problem: Having 2 textfields (text1 (input),text2 (dynamic)). When text1 is filled by a number I want to mulitply that number wích 10 and show the result in text2. I´m really new to AS and have been trying to acieve this by usin variables with the textfields but I must be missing something ´cause it won´t work for me.

Problem2: Same as above but now I have 1 textfield (dynamic) and a check box and on true I want to have the string 10 to show in my textfield. Same here been browsing the macromedia site but I must be a moron ´cause I can´t figure it out.

Pleas help

Problem 1)

Create your input textfield, give it the INSTANCE name of “num” (no quotes). Create your dynamic textfield and give it the INSTANCE name of “ans” (no quotes).

Now on a frame apply these actions…
[AS]num.text = 0;
num.restrict = “0-9”;
this.onEnterFrame = function() {
var newNum = parseInt(num.text)*10;
ans.text = newNum;
This first assigns the value of 0 to your num input box. Then it uses the restrict feature to allow only the keys 0-9 on the keyboard to be used in the input field. After that an onEnterFrame dynamic event handler is use so that the value will always be checked.

The variable newNum takes the value of the number in your textbox (parses it to an integer first using parseInt) and multiplies it by 10. Then it sets the value of your ans textfield to be equal to the value of the newNum variable.

Problem 2)

Not sure I understand exactly, so you want the checkbox to be checked, and have 10 show in your dynamic textfield? If so are you using a checkbox component? This will assume you are…

Create a dynamic textfield with the INSTANCE name “ans” (no quotes).

On a frame add these actions…
[AS]function onSubmit() {
ans.text = 10;

This creates a function that we can call with our checkbox that will set the ans texfields value to 10.

Now drag an instance of the checkbox component onto the stage, click on it, open up the properties panel, and under “Label” put 10 and under “Change Handler” put “onSubmit” (no quotes).

I hope I helped.

regarding problem 1…

why don’t you use num.onChanged instead of the onEnterFrame handler? =)

Because I didn’t think of it and I didn’t have Flash opened to test how well that worked anyway :stuck_out_tongue:


trust me… it works fine. :wink:

Yeah, it does.

[AS]num.text = 0;
num.restrict = “0-9”;
num.onChanged = function() {
var newNum = parseInt(this.text)*10;
ans.text = newNum;

Thank you very much!!!
That´s what I wanted, can´t tell you enough how much I appriciate your help.:slight_smile:

Spoke to soon. The check box code I can´t get to work. I´ll attach it as a last cry for help.

Oh no I´m making a fool out of my self. I forgat to chantge the color of the text in my textfield?:nerd:

Ok I´ve got it all down and thanks alot.
Now another problem arises.
When I checked one of the check boxes and the textfiel picks that up and displays a number.
How do I change that value when I uncheck the check box. I guess I`ll have to use some kind of boolean value to acomplish this.
Please bear with me.

Alright, now you please bear with me, I do not use components, never have, probably never will for anything (except maybe the scrollbar component if I am feeling lazy) so I am not sure if this is the best way to do this…

What you will need to do is have some kind of variable to check if it is true or false and check that value and decided what to do…

I also noticed that you have your checkbox checked as true to start off with, so we will have to run the function as soon as the frame is hit so it updates the textfield right away…

[AS]var trigger = true;
function onSubmit() {
if (trigger) {
ans.text = 10;
trigger = false;
} else if (!trigger) {
ans.text = 0;
trigger = true;

Ok tried that and it worked but when I added another checkbox and wanted to add a variable to it (triggercd) it started to behave strange. I´m attaching the code to se if you can see some imedate problems with it. If you need the fla just tell me and I´ll attach it
var trigger = true;
function tshirt() {
if (trigger) {
sumtshirt.text = 10;
shirt.text = " Textstring";
trigger = false;
} else if (!trigger) {
sumtshirt.text = 0;
shirt.text = “”;
trigger = true;

var triggercd = true;
function cd() {
if (triggercd) {
sumcd.text = 15;
happy.text = " Textstring";
trigger = false;
} else if (!trigger) {
sumcd.text = 0;
happy.text = “”;
trigger = true;

[/AS] :slight_smile: :slight_smile: :slight_smile:

Oh I noticed the onSubmit; in the end of the code I removed that but It still behaves the same.

I noticed that I forgot to change the trigger to triggercd but it still behaves strange.

Heureka now I got it working. Phew!!!

Thanks alot lost

This AS thing is a bit of a handful for me…so far anyway.

You will hear from me again =)

LOL, sounds like you had an exciting night (or day, or whatever depending on your time zone)