17 Replies Latest reply on Jul 13, 2007 3:45 PM by cayennecode

    Math in Flash

    wcheshier
      I'm building a Flash calculator to calculate system specifications. When I publish the file using Flash Player 8, I get NaN for answers. When I change to Flash Player 7 it works swell.
      If I set the text variables to initial strings, they evaluate as numbers and do the math properly. When I enter a new number, I get NaN.
      Here is an simplified version of what I'm doing:
      on the stage are two input text fields with their Var settings set to "freakin1" and "freakin2", one Dynamic Text Field with Var set to "freakinanswer" and a button named "mcFreakingButton"

      //action script
      var freakin1:String = "2";
      var freakin2:String = "3";

      mcFreakingButton.onRelease = function() {
      freakinanswer = Number(freakin1) + Number(freakin2);
      trace(Number(freakin1));
      trace(Number(freakin2));
      };
        • 1. Re: Math in Flash
          Level 7
          I just tried that using Flash 8 and it worked fine saving to Flash 8
          player, using either AS1 or AS2.

          I don't know of any other settings that could get in the way.
          • 2. Re: Math in Flash
            kglad Adobe Community Professional & MVP
            and what's the problem with the code you showed?
            • 3. Re: Math in Flash
              wcheshier Level 1
              If my publish settings are on Flash Player 8, It returns NaN for the "freakinanswer" text and the trace statements when new input is added.
              if publish settings are for Flash Player 7, it works.

              I'm currently publishing to 7 to have the file up and running, but if I need this functionality with Flash 8 features I don't want to be hosed.
              the actual (published as a fp7) file I want this for can be seen at hydrus.com/calculations.html
              • 4. Re: Math in Flash
                kglad Adobe Community Professional & MVP
                your freakin textfields are probably html-enabled, have auto-kern ticked or something equivalent. what do you see when you use trace(freakin1), for example, after entering a number in that textfield?
                • 5. Re: Math in Flash
                  wcheshier Level 1
                  html and kerning are off.
                  If I click "mcFreakingButton" to get "freakinanswer" without entering new values (i.e. using the values defined when I instantiate the "freakin1" and "freakin2" variables) it works. When I enter numbers into the Input text fields, I get NaN.
                  • 6. Re: Math in Flash
                    kglad Adobe Community Professional & MVP
                    re-read my mesage and report the results.
                    • 7. Re: Math in Flash
                      wcheshier Level 1
                      If I trace(freakin1) instead of Number(freakin1) as I have above, I get:
                      <TEXTFORMAT LEADING="4"><P ALIGN="LEFT"><FONT FACE="arial" SIZE="28" COLOR="#000000" LETTERSPACING="0" KERNING="0">3</FONT></P></TEXTFORMAT>
                      in the output window and NaN in the freakinanswer field

                      I did verify that the render text as HTML button is off.
                      • 8. Re: Math in Flash
                        wcheshier Level 1
                        In case I'm too obtuse to follow or if I'm steaming anyone's beans, I put the FLA, the SWF and the code on my web site
                        willcheshier.com/darnMath.html

                        thanks
                        • 9. Re: Math in Flash
                          Greg Dove Level 4
                          I downloaded your fla to take a look. I loaded it in flash 8. You have auto-kerning enabled for both of your input fields fk1 and fk2 and fk2 is html enabled. Take those away and it works.
                          • 10. Re: Math in Flash
                            wcheshier Level 1
                            ?
                            I did inadvertently turn on html in the file I posted (i'm a twit) so I turned it back off.
                            My Auto kern box in the Properties window is grayed out for the two input text fields and the Dynamic text field.
                            I'm on a Mac, does that matter?
                            • 11. Re: Math in Flash
                              kglad Adobe Community Professional & MVP
                              no, it doesn't matter what computer you're using. your trace reveals you have exactly the problem i mentioned.

                              click on an empty part of the stage and then click on one of your input textfields. is html-enabled or auto kern ticked? if so, fix it and retest.

                              as long as you see <TEXTFORMAT... etc, your textfield is still html enabled.
                              • 12. Re: Math in Flash
                                wcheshier Level 1
                                I got the fields to work by converting them from Input to Static text fields. Then and only then was Auto Kern available. I turned Auto Kern off and then set the text fields back to Input fields. Then it worked. Weird, huh?

                                Should Auto Kern be available when the text field is set as Input Text? Is Flash somehow wonked on my system?

                                In either case, thanks to all who replied for your time and help.
                                • 13. Re: Math in Flash
                                  kglad Adobe Community Professional & MVP
                                  yes, auto kern should be available for all textfield types. i'm not sure if it's available for all fonts, but i've never seen a font for which it is not available.
                                  • 14. Re: Math in Flash
                                    wcheshier Level 1
                                    On my personal and work copies (both Mac versions) Auto Kern isn't an available selection on an Input or Dynamic text field.

                                    Any other Mac users out there who can chime in? I'd like to know if I just have something set goofy or if Adobe/Macromedia did something goofy on the Mac version.
                                    • 15. Re: Math in Flash
                                      Level 7
                                      Flash 8 on a Mac has Auto kern greyed out for both Input and Dynamic
                                      Text. On Windows Auto kern is set to On by default for both Input and
                                      Dynamic, as well as Static.

                                      On the Mac version Auto kern is set to Off by default for Static text.

                                      Flash CS3 on a Mac has Auto kern greyed out for both Input and Dynamic
                                      text, it is set to On by default for Static Text.

                                      I don't have a Windows copy of Flash CS3 to check.

                                      In testing your first example again, it will work fine if the render as
                                      HTML option is not selected for either of the input text fields.
                                      • 16. Re: Math in Flash
                                        kglad Adobe Community Professional & MVP
                                        that's not very nice of adobe.
                                        • 17. Re: Math in Flash
                                          cayennecode Level 1
                                          I get the feeling adobe's Flash IDE developers has been stretched too thinly, and the Macintosh version has suffered.