Flex 4:具有滑块和文本框组合
在一个 Flex 项目中,我在表单上有一个滑块和文本框,我可以使用滑块(为了方便)或文本输入(为了精确的数字)来寻求用户输入。根据其中任何一个的用户输入,我通过附加的侦听器更新另一个,该侦听器调用相关函数
slider.addEventListener("change",sliderUpdate);
textIn.addEventListener("change",valueUpdate);
我在文本输入方面遇到问题,它不允许我键入十进制数字 - 这可能正在发生因为我有一个侦听器,它为文本输入中的每次击键增加滑块,因此无法接受“.”。例如 .05、.1、.00003
我该如何解决这个问题 - 我可以将文本输入侦听器保持在延迟状态,直到我可以按 Enter 键表示我已完成吗?
On a flex project, I have a slider and text box on a form whereby I seek user input using either the slider(for ease) or the textinput(for precise numbers). Based on user input on either of these, I update the other via a listener attached, that calls the relevant functions
slider.addEventListener("change",sliderUpdate);
textIn.addEventListener("change",valueUpdate);
I am having problems with the textinput in that, it doesn't allow me to key in a decimal number- this is probably happening as I have a listener that is incrementing the slider for every keystroke in textinput and hence unable to accept a ".". e.g. .05, .1, .00003
How do I get around this- can i hold the textinput listener to holdoff till I can press an enter to indicate I am done?
这对我有用:
滑块的步长值为 0.01;如果您在文本字段中输入值,滑块应自动更新。
编辑:
然后在 TextInput 上,您应该侦听 keyDown 事件 (KeyboardEvent.KEY_DOWN),并且该函数应该检查按下的键是否为 ENTER,然后更新滑块:
该函数:
如果您更喜欢使用addEventListener 这应该做到这一点:
This works for me:
The slider's step value is 0.01; If you input a value in the text field the slider should automatically update.
EDIT:
Then on the TextInput you should listen for the keyDown event (KeyboardEvent.KEY_DOWN) and the function should check if the key pressed is ENTER and then update the slider:
The function:
If you prefer to use addEventListener the this should do it: