11 Replies Latest reply on May 24, 2006 6:41 PM by ONG_Sam

Good Day All:

Much of my appreciation if someone my help on this - which I believe is easy to those expert...

I manage to create the onPress based on text field but if I applied to number, it doesn't seem working. The code is as simple as:

if a number if pre-assign to a and/or b, it works but the result in c should be lively. or it returns me NaN.

var myButton:Button;

pButton.onPress=function():Void
{

trace(c=a+b);
};
• ###### 1. Re: Adding Number On Event
I'm not really sure if i understand your problem (providing the fla would do the trick though i guess)

If you wnat the value of c trced you should use
trace("c = "+a+b);

if your result for the case a = 1 and b = 2 isn't "3" but "12", then a and b were treated as strings nut as numbers (depends on how you define a and b)

You should use

trace ("c = "+Number(Number(a) + Number(b)));
(that is the 110 % way ;-))
• ###### 2. Re: Adding Number On Event
Many tx "2m" for your kind reply, truly appreciate it...you got my question right and the "logic" of your reply is true...BUT, I don't know what I has done wrong, it still replies me "NaN". The coding is as simple as below. I got field a, b and c. If 3 of the fields are string, no problem it concatenate a and b. As soon as I want to calculate a+b, it doesn't work:

c.onSetFocus=function():Void
{
(c.text = a.text + b.text);
}

c.onSetFocus=function():Void
{
("c = "+Number(Number(a) + Number(b)));
};

Pls comment and highlight. Many tx.
• ###### 3. Re: Adding Number On Event
Maybe you could provied the fla, and I could take a look, that might shorten the process ;-)
• ###### 4. Re: Adding Number On Event
c.text=parseFloat(a.text)+parseFloat(b.text)
• ###### 5. Re: Adding Number On Event
Morning 2m: Good idea to send you the fla as it's respectively small, just 3 lines of code but when i click on the attach code, it gives me a screen to include raw html code?!

Rothrock: I tried yours, same problem NAN. Many thanks!

as mentioned by 2m, could be some timy mistake I made, which myself believe so but I have caught on this for sometime

• ###### 6. Re: Adding Number On Event
Well mine covers the basics – there may well be a scope issue.

You need to do some traces to see where your info is going bad. So do this:

trace("The text of a is: "+a.text);
trace("The value of a is: "+parseFloat(a.text);

What do you get with that?

BTW, you can't attach a whole FLA with the attach code button. That is only for pasting in code that you copy out of your file. But we know that isn't working so attach code won't help you here.
• ###### 7. Re: Adding Number On Event
Hi,

by providing the fla, I ment that you could upload it to some server and tell us the url to download it.
(If that's not an option, send me a private message with your email, I'll answer and you can send it to me via email)
• ###### 8. Re: Adding Number On Event
Gentlement, I think I'm the most happy lady at this moment. GOOD NEWS to share, it works. MANY MANY TX the prompt reply and tips. Special tx to 2m & Rothrock. Truely appreciate it. tk care until we "see" again.
• ###### 9. Re: Adding Number On Event

Nice to know that I have helped making you happy.

Don't tell my wife though ;-)

CU
• ###### 10. Re: Adding Number On Event
So what was the trick? Please share so that anybody else who finds this thread can learn from you.
• ###### 11. Re: Adding Number On Event
I wanted to share and not hoping anyone will be caught as me and "shy" to ask this question as it's simply...sorry to trouble you all....BUT......

I may only say I "suspect" "event" is the culprit....when I do "onSetFocus", both of your (2m & Rothrock codes) work, BUT "onPress", it doesn't work. Anyhow, strangley when I change the instance name to a, b & c, instead of using cName,fname&lName, it works.

Logically I don't see the instance name is the cause...I really get quite confuse but no more time for me to futher explore...need to rush for projects....

Anyhow, many thanks...and for those who caught with this - good luck!!!