8 Replies Latest reply on Sep 28, 2010 2:31 AM by Yiroon

    numericStepper - how to get the manual text input

    JWPB

      I have a numericStepper that has a change"  listener  that works just fine when using the up/down keys on the stepper (I can retrieve the value of the numericStepper). However, if the user manually types in a value and then clicks away from the stepper, I can't retrieve the value of the stepper.

      From researching the web, I know that the "change" event is only activated via the up/down arrows on the numericStepper OR when the user presses the enter key in the numericStepper text field.

       

      But, I don't want the user to have to press Enter (they would not always understand that they have to do that - especially since there are multiple fields on the screen.

      So, I need to use the "focusOut" event. (right?)

       

      My problem, I cannot retrieve the manual value typed into the numericStepper.  The ".value" property always contains the last value set by the up/down arrows or pressing Enter.

       

      For example,

      •      the value in the numericStepper shows     75
      •      I manually enter     65 and then click away from the numericStepper and go into another field.
      •      The  numericStepper still shows  65, but when I trace the .value of the numericStepper, it still shows 75.

       

      QUESTION: How do you get the textInput value of the numericStepper?

       

      Thank you, Julia

       

      -------------------------------------------

      THis is my change event handler. The instance name of the numericStepper is "payRate_step" and I'm saving the value into the variable "newString"

       

      var RatestepListener:Object = new Object();

      RatestepListener.change = function(evt_obj:Object){

           var newString:String = evt_obj.target.value;

      }

      payRate_step.addEventListener("change",RatestepListener )

        • 1. Re: numericStepper - how to get the manual text input
          kglad Adobe Community Professional & MVP

          use the textField property of your stepper to access its textinput.  you can then use the textinput properties and events to do what you want.

          • 2. Re: numericStepper - how to get the manual text input
            JWPB Level 1

            I have been able to answer my own questions, but not sure if this is the best way to handle the problem.

             

            Because I don't have any buttons on my screen along with the numericStepper, there isn't anything that "focuses on another event". I only have text input fields and numericSteppers on my screen.  I noticed that some of the examples on the web have buttons that when pressed, the flash file would  pick up a manual value entered into a numericStepper.

             

            Playing around with the focusIn and focusOut, I found that if I use the focusIn on another object, that the flash file automatically updated the numericStepper.value to the value I entered manually. I remove the listener once I have retrieved the value of the numericStepper.

             

            So, my solution (until something else comes out of this)

             

            1. added 

             

            //when focusOut of the numericStepper, add the 'focusIn" listeners for the other objects

            var fieldListenerFocusOut:Object = new Object();

            fieldListenerFocusOut.focusOut = function(evt_obj:Object){

            trace("focusOut = "+evt_obj.target.value);

            otherInstance.addEventListener("focusIn",fieldListenerFocusIn )

            }

            ns.addEventListener("focusOut",fieldListenerFocusOut )

             

            //when focusIn on the numericStepper, remove the 'focusIn" listeners for the other objects.

            var RatestepListenerFocusIn:Object = new Object();

            RatestepListenerFocusIn.focusIn = function(evt_obj:Object){

            trace("focusIn pay or bill");

            otherInstance.removeEventListener("focusIn",fieldListenerFocusIn )

            //execute commands  to retrieve the value of the numericStepper whether manually input or uses up.down arrows

            }

            ns.addEventListener("focusIn",RatestepListenerFocusIn )

             

            //this listener for "focusIn" on those text fields besides the numericStepper. So when click away from the numericStepper,

            //flash focuses on something else - and so picks up the manual input value of the numericStepper

            var fieldListenerFocusIn:Object = new Object();

            fieldListenerFocusIn.focusIn = function(evt_obj:Object){

            trace("focusIn other fields = ");

            //execute commands

            }

             

             

            This could be very memory intensive, but it is a small program and will work till something better comes along.

             

            Any other thoughts, I'd appreciate it. Hope this helps someone else.

            Julia

            • 3. Re: numericStepper - how to get the manual text input
              JWPB Level 1

              I tried accessing the textField property of the stepper, but could not come up with the correct syntax. I used the debug to check the value also, and it was never updated with the manually input value in any of the variables associated with the stepper - including the TextValue.

               

              I tried the two options below, but both give me undefined:

                   ns.textValue.value;

               

                   ns.TextField.text                 

               

               

              ----------------

              What would be the syntax to access the numericStepper's textinput?

              • 4. Re: numericStepper - how to get the manual text input
                kglad Adobe Community Professional & MVP

                read the above message.

                • 5. Re: numericStepper - how to get the manual text input
                  kglad Adobe Community Professional & MVP

                  that should in inputField in as2, textField in as3.  my mistake.

                   

                  if ns is your stepper, use:

                   

                  import mx.controls.TextInput
                  var ti:TextInput = ns.inputField;

                  var tiLO:Object={};
                  tiLO.change=function(eobj:Object){
                      trace(eobj.target.text);
                  }
                  ns.editable=true;
                  ti.addEventListener("change",tiLO);

                  • 6. Re: numericStepper - how to get the manual text input
                    JWPB Level 1

                    Thank you dglad,

                     

                    That did the trick.

                     

                         ns.inputField.text;  //as2   or in as3       ns.TextField.text;

                     

                    Thank you very much.

                    Julia

                    • 7. Re: numericStepper - how to get the manual text input
                      kglad Adobe Community Professional & MVP

                      you're welcome.

                       

                      (but for as3, that should be:  ns.textField.text)

                      • 8. Re: numericStepper - how to get the manual text input
                        Yiroon

                        Could it be that this doesn not work in Flex 3.5 anymore?

                         

                        ns.textField.text does not compile. NumericStepper does not have a (public) member textField.

                         

                        It seems that this NumericStepper shortcoming got fixed in Flex 4 as there the doc says (emphasis added):

                         

                        An input value is committed when the user presses the Enter key, removes focus from the component, or steps the NumericStepper by pressing an arrow button or by calling the changeValueByStep() method.

                         

                        That doesn't solve the problem in Flex 3.5 though. Any ideas?