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

    Adding Number On Event


      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.

      Many thanks in advace for your help!

      var myButton:Button;


        • 1. Re: Adding Number On Event
          2m Level 2
          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
            ONG_Sam Level 1
            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.text = a.text + b.text);

            as per your advise, I changed it to:

            ("c = "+Number(Number(a) + Number(b)));

            Pls comment and highlight. Many tx.
            • 3. Re: Adding Number On Event
              2m Level 2
              Maybe you could provied the fla, and I could take a look, that might shorten the process ;-)
              • 4. Re: Adding Number On Event
                Rothrock Level 5
                • 5. Re: Adding Number On Event
                  ONG_Sam Level 1
                  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
                    Rothrock Level 5
                    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
                      2m Level 2

                      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
                        ONG_Sam Level 1
                        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
                          2m Level 2

                          Nice to know that I have helped making you happy.

                          Don't tell my wife though ;-)

                          • 10. Re: Adding Number On Event
                            Rothrock Level 5
                            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
                              ONG_Sam Level 1
                              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!!!