This is not working, why?

Why is this not working

I have 3 inputs, and 3 dynamic text boxes,

a , b, e are input boxes, d, c and f are output
But f is not working?

[AS]
a = 0;
b = 0;
e = 0;
_root.onEnterFrame = function() {
c = a*b;
d = c + ((c/100)*21);
f = e + ((e/100)*21);
}
[/AS]

If nessecary I will give the fla…

Anyone?

i’m not sure but i think flash doesnt show the ‘0’ variable…
Try with non null variables for a,b and e and check if it works better…

“a” and “b” work?

Wait, I’ve posted the fla

Oops, wrong one

what do those return to you?

Well look at it…

a = 0
b = 0
e = 0
c = a*b

Well if a AND b are both 0, then 0*0 will return 0.

SO d = c+((c/100)*21); will return d = 0+((0/100)*21);

And f = e+((e/100)*21); will return f = 0+((0/100)*21);

well duh… :stuck_out_tongue: I know that. I figured that they weren’t returning the right thing so since they seem like they are supposed to be returning 0 then they aren’t… you get it?

I did pass Calculus… i can add and multiply :):):P:trout:

Oh… haha Jubba, I wasn’t replying to your reply… although now I see it does look like that…ooooops.

I was responding to Didius on why it wasn’t working, because all it will return is 0, so how will it work?

Since his example file didn’t work (supposing he is on a Mac since there are issues with attaching .fla files when you use a mac…zipping them fixes that) I couldn’t check out what he was doing, so I assumed this was the issue.

i see… interesting… ok then. :slight_smile:

he’ll have to come back and give us a better file!

Alright, I’m back

I’m not a mac user lost, The file was just enormous and my modem kind of crashed.

Anyway, here is the right file…

I’ll gues you will see the problem right away…

Well I can’t say as I do see your problem.

The only problem I can see is that

a = 0;
b = 0;
e = 0;

If they all equal 0, then

c = a*b;
d = c+((c/100)*21);
f = e+21;

Will all be equal to 0 as well :-\

And I don’t get why you run it onEnterFrame :-\

What exactly are you trying to do?

My mother is always saying i’m doing nothing all day (she right, but I don’t like to admit) So I decided to make something wich helps her administration. She should just enter the money she paid and the money she got, and then she would be able to see the balance. But it’s not working.

I’ll post a detailed fla right away…

The second thing is not working.

If you enter a number, ex: 5. He will not show 27 (taxes inc) but he will paste it together; “521”; 5 and 21…

get it?:elderly:

(forgive my explanation, my english *****)

Well it is a very simple solution, but the problem itself has me confused to no end. For some reason your script is parsing “e” as text so you are telling “f” to display the text inside “e” and 21 at the end of that.

Why it is only doing it for that textbox I have no clue since you have a whole bunch of other textboxes that work fine.

The solution is to use parseInt() which parses a string into an integer (given that string is an actual integer and not text)

[AS]a = 0;
b = 0;
e = 0;
_root.onEnterFrame = function() {
c = a*b;
d = c+((c/100)*21);
f = parseInt(e)+21;
};[/AS]

What you could ALSO do here is give the textbox the INSTANCE name of the letter instead of the VAR name.

Why do this? Easy… because you can use “restrict” on the textbox that way :slight_smile:

[AS]a.restrict = b.restrict=c.restrict=d.restrict=e.restrict=f.restrict=“0-9”;
a.text = b.text=e.text=0;
_root.onEnterFrame = function() {
c.text = a.text*b.text;
d.text = parseInt(c.text)+((c.text/100)*21);
f.text = parseInt(e.text)+21;
};[/AS]

This restricts your input boxes to only be able to accept the characters 0-9 :slight_smile:

And oh yeah, while we are at it, you see how I chained my restricts and such. Why? Because ya can :stuck_out_tongue:

When the value of certain things are going to be the same you can string them a long like that.

For example… a.text, b.text, and e.text are all going to be equal to 0. Instead of writing down

a.text = 0
b.text = 0
e.text = 0

You can just write…

a.text = b.text = e.text = 0

:slight_smile:

Cool, That really helped me out! Thanks a lot

Why didn’t flash wanted to accept mine?? I still don’t understand. Anyway, it’s working now.

Stil I do not get wat you do over here: can you explain that to me more detailed please?

Originally posted by lostinbeta *
[AS]a.restrict = b.restrict=c.restrict=d.restrict=e.restrict=f.restrict=“0-9”;
a.text = b.text=e.text=0;
_root.onEnterFrame = function() {
c.text = a.text
b.text;
d.text = parseInt(c.text)+((c.text/100)*21);
f.text = parseInt(e.text)+21;
};[/AS]

BTW: Thanks for the last hint…
:battery: 's up again

[AS]a.restrict = b.restrict=c.restrict=d.restrict=e.restrict=f.restrict=“0-9”;
a.text = b.text=e.text=0;
_root.onEnterFrame = function() {
c.text = a.text*b.text;
d.text = parseInt(c.text)+((c.text/100)*21);
f.text = parseInt(e.text)+21;
};[/AS]

This goes by if your textboxes have the INSTANCE names of a, b, c, d, e, and f. According to your file you have their VAR names as the letter (which is all well and good for the original way you had it, but for what I did here it needed to be the instance name).

[AS]a.restrict = b.restrict=c.restrict=d.restrict=e.restrict=f.restrict=“0-9”;[/AS]

The line above uses restrict feature in Flash to restrict the characters you can use in your input textbox. In this case, only the characters 0-9 can be used. Since there is no need for letters in this case… why allow the chance of accidently hitting one?

[AS]a.text = b.text=e.text=0;[/AS]

As for this line above, well you probably already know what it does… but you may not know why I use .text.

When going by the instance name of a textbox you MUST use .text to be able to add text into the textbox, or retrieve the value of the string in the textbox. You don’t need to add .text when you are using the VAR name (actually it won’t work if you do), but you have to use it when you are using an INSTANCE name for your textbox.

That help at all?

That’s just perfect!

Thanks Lost…

Glad I could help :slight_smile:

lost to the rescue again…

i’m confused no end to what it all means but it looks great ha ha