Actionscript - numericStepper component + KeyUp

Hi.

I'm having problems getting the numeric stepper values when I use the keyboard to write the values.
I would like to set the numericstepper value each time I press a number.

I know the arrow keys is a way but I have a wide range of values and don't want to go fom 0 to 99999 using the up arrow key.

this is working:
      var stepper:mx.controls.NumericStepper = this.a_emp;
      var listToStepper:Object = {};
      listToStepper.change = function(eventObj:Object):Void{
            stepper_val = eventObj.target.value;
            a_emv.value      =      a_val_ini * stepper_val/100;
            recalc();
      }
      stepper.addEventListener("change", listToStepper);



now I need the following too, and it is not working rigth:

      var stepper:mx.controls.NumericStepper = this.a_emp;
      var listToStepper:Object = {};
      listToStepper.keyUp = function(eventObj:Object):Void{
            
            //stepper_val = eventObj.target.value.doLater();
            //this.a_emp = doLater();
            stepper_val = eventObj.target.value;
            a_emv.value      =      a_val_ini * stepper_val/100;
            recalc();
            trace("keyUp: " + stepper_val);
      }
      stepper.addEventListener("keyUp", listToStepper);

And the trace output is allways (0) the initial value that is set in the component



Thank you for reading this, and for your help! ;)



valverde2006Asked:
Who is Participating?
 
GuicCommented:
I 'm afraid that is not possible easily.
Because you need to tell to the application when you have finished to enter your number.

If you press 2 and after 5 : the question is, do you want the number 2 and after 5 on your Numericstepper or your want 25.

You can put a setInterval function that will "enter" automatically after 1 second of inactivity.
So when you will let a intervall of one second between 2 numbers, it will "press Enter" by himself.

But the users would be surprised !

Regards
0
 
valverde2006Author Commented:
Ok, using Enter after write the number, works. It is good but would bee better if it was on KeyUp
0
 
GuicCommented:
Hi,

what would you like with the Keyup ? increment your stepper when you have the focus on the stepper, or without the focus ?

Regards
0
 
valverde2006Author Commented:
Hi Guic,

on keyUp, eg: after pressing the keyboard number 3, I want to set the numericStepper value to 3 without needing to press "Enter".

0
 
Aneesh ChopraCommented:
hi,

I assume you numericStepper component instance name is "stepper"

following code will work for you:
----------
myKeyListener = new Object();
myKeyListener.onKeyUp = function() {
      myvalue = String.fromCharCode(Key.getAscii());
      if (myvalue<10) {
            stepper.value = myvalue;
      }
};
//
Key.addListener(myKeyListener);
-----------

Rgds
Aneesh
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.