Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to change Numeric Stepper value by keyboard input

Explorer ,
Apr 01, 2011 Apr 01, 2011

Help please!

I hope you can save me on this one:

How can I actually change the Numeric Stepper value by entering a number via keyboard without having to press enter or click another Numeric Stepper?

I've tried everything, including keyboard events, but had no success.

All I want is, as soon as I type a number, the numeric stepper value changes to it.

Any ideas?

Thank you so much!

TOPICS
ActionScript
1.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Apr 01, 2011 Apr 01, 2011

I anticipated you wanting more than you described, but you need to make sure your stepper has a maximum sufficient to handle the values you might expect to enter.

stage.addEventListener(KeyboardEvent.KEY_UP, keyUsed);

var numBuilder:String = "";

function keyUsed(event:KeyboardEvent)
{
  if(event.charCode >= 48 && event.charCode <= 57){
   numBuilder += String(event.charCode - 48);
      stepper.value = Number(numBuilder);
  } else {
   numBuilder = "";
  }
}

As far as managing different steppers with the sa

...
Translate
LEGEND ,
Apr 01, 2011 Apr 01, 2011

Here's one way...

stage.addEventListener(KeyboardEvent.KEY_UP, keyUsed);

function keyUsed(event:KeyboardEvent)
{
  if(event.charCode >= 48 && event.charCode <= 57){
   stepper.value = event.charCode - 48;
  }
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 01, 2011 Apr 01, 2011

Thanks a lot Ned!

Unfortunaly, it only works correctly if the value is less than 10, since it only captures the last KeyboardEvent. Plus, since I have more than one Numeric Stepper, it would change all of them at the same time (although I could look for which one is on focus.. hum.. and maybe only then capture the keys into a string... I could try that).

Thanks a lot for the pointers!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 01, 2011 Apr 01, 2011

I anticipated you wanting more than you described, but you need to make sure your stepper has a maximum sufficient to handle the values you might expect to enter.

stage.addEventListener(KeyboardEvent.KEY_UP, keyUsed);

var numBuilder:String = "";

function keyUsed(event:KeyboardEvent)
{
  if(event.charCode >= 48 && event.charCode <= 57){
   numBuilder += String(event.charCode - 48);
      stepper.value = Number(numBuilder);
  } else {
   numBuilder = "";
  }
}

As far as managing different steppers with the same code goes... good luck.  I don't think Flash has the ability to read minds yet and determine which stepper you are thinking of when a key is pressed.  Anyway, you have a solution for what you initially asked for.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 13, 2011 Apr 13, 2011
LATEST

Thanks a lot for your help. I have actually dismissed the numeric stepper component and made my own, using buttons and text field. It worked better for me.

Again, thanks for your help and code!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines