9 Replies Latest reply on Jun 1, 2006 11:27 AM by 2m

    VERY easy question...

    DIY_Lobotomy Level 1
      I put the following code in so that you can only type numbers and periods into a text field named "labor_txt":

      labor_txt.restrict = "0-9 .";

      For some reason it's only restricting it to numbers and not letting me type periods. Do you know what I'm doing wrong here???...

      Thanks!...
        • 1. Re: VERY easy question...
          Level 7
          DIY_Lobotomy,

          > I put the following code in so that you can only type numbers
          > and periods into a text field named "labor_txt":
          >
          > labor_txt.restrict = "0-9 .";

          That would allow numbers, periods, and spaces. But sure, that's pretty
          straightforward.

          > For some reason it's only restricting it to numbers and not letting
          > me type periods. Do you know what I'm doing wrong here???...

          I tried this just now and am able to type numbers, periods, and spaces.
          What happens if you isolate just this scenario in a new, otherwise
          uncluttered FLA?


          David
          stiller (at) quip (dot) net
          Dev essays: http://www.quip.net/blog/
          "Luck is the residue of good design."


          • 2. Re: VERY easy question...
            2m Level 2
            trextfield.restrict = "0123456789",
            or textfield.restrict = "a-z";
            • 3. Re: VERY easy question...
              DIY_Lobotomy Level 1
              As you can see from my original post, I sort of did that, and it works to restrict it just to numbers. But I need it restricted to numbers AND periods. I thought just adding " ." after the "0-9" would do it, but I guess not. Any ideas?...

              --Matt
              • 4. Re: VERY easy question...
                2m Level 2
                sorry tried to be too efficent it seems, not fully reading your post.

                But this time I tried, and it works with me.(The way you did it) Could it be, that you embed fonts, and don't embed the period?
                • 5. Re: VERY easy question...
                  DIY_Lobotomy Level 1
                  I don't think I did that. Not sure. Here - you can check out the .FLA here (that line of code is on the actions in the 5th frame):

                  http://al-i.anixter.com/TEMP/pie.fla

                  Thanks!...
                  • 6. Re: VERY easy question...
                    Level 7
                    DIY_Lobotomy,

                    > I don't think I did that. Not sure. Here - you can check
                    > out the .FLA here (that line of code is on the actions in
                    > the 5th frame):

                    There's a lot of stuff going on in frame 5 ... much of it is a bit
                    confusing (to me, anyway), some unnecessary, and some simply incorrect. For
                    example, look at these lines here ...

                    empty_mc.onEnterFrame = function(){
                    tech = parseInt(tech);
                    labor = parseInt(labor);
                    minutes = parseInt(minutes);
                    // etc.

                    I *think* what you're after is a way to make sure the values of these
                    text fields are numerical. parseInt() will do this, for sure, but by
                    definition, parseInt() returns an integer -- that is, no decimal places.
                    Maybe you want parseFloat()? Or maybe just Number()?


                    David
                    stiller (at) quip (dot) net
                    Dev essays: http://www.quip.net/blog/
                    "Luck is the residue of good design."


                    • 7. Re: VERY easy question...
                      2m Level 2
                      You are a nasty boy! using variables on textfields instead of vorking with textField.text is no only very lazy an soooo Flash 5, but also very dangerous, especially when you work with them onEnterFrame (bad boy!!)

                      when you check set labour = labour_txt.text - that way you don't change the contents of the input field when working with the value. and remove the variable from the field.
                      and if you want to be a real good boy -
                      replace onEnterFrame with some onChange listener to the textfields, that saves resources.
                      • 8. Re: VERY easy question...
                        DIY_Lobotomy Level 1
                        Yes - I (admittedly) probably overcomplicated things. But that's just cuz of my lack of knowledge w/ actionscript. But even taking into consideration those things that you mentioned, that shouldn't affect the simple one line of code that is supposed to restrict my text fields, right? Or am I wrong about that? And if so, what could fix it?...
                        • 9. Re: VERY easy question...
                          2m Level 2
                          Let me expain:

                          You with every tick of a frame (several times a second) you convert the value of labor into an integer (see davids post about that) and as labor is hardwired to the content of your textfield it is update instantly, so even befor your period is drawn your function changes the value.

                          Proof putt 378502 in the field, the click between 8 and 5 and type a period, you'll loose the 502, because your new number is converted.

                          Maybe now you can understand what causes your problem, and take my hints from the last post to good use.

                          (I got to go for a while - sorry)