forms - Flex 4: Having slider and textbox combo -
on flex project, have slider , text box on form whereby seek user input using either slider(for ease) or textinput(for precise numbers). based on user input on either of these, update other via listener attached, calls relevant functions
slider.addeventlistener("change",sliderupdate); textin.addeventlistener("change",valueupdate); i having problems textinput in that, doesn't allow me key in decimal number- happening have listener incrementing slider every keystroke in textinput , hence unable accept ".". e.g. .05, .1, .00003
how around this- can hold textinput listener holdoff till can press enter indicate done?
this works me:
<?xml version="1.0" encoding="utf-8"?> <s:application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minwidth="955" minheight="600"> <fx:script> <![cdata[ import spark.events.textoperationevent; protected function sliderupdate(event:event):void { textin.text=slider.value.tostring(); } protected function valueupdate(event:textoperationevent):void { slider.value=number(textin.text); } ]]> </fx:script> <s:hslider id="slider" x="10" y="106" width="308" change="sliderupdate(event)" maximum="100.0" minimum="0.0" stepsize="0.01"/> <s:textinput id="textin" x="10" y="76" width="87" change="valueupdate(event)" text="0"/> </s:application> the slider's step value 0.01; if input value in text field slider should automatically update.
edit:
then on textinput should listen keydown event (keyboardevent.key_down) , function should check if key pressed enter , update slider:
<s:textinput id="textin" x="10" y="76" width="87" keydown="textin_keydownhandler(event)" text="0"/> the function:
protected function textin_keydownhandler(event:keyboardevent):void { if (event.keycode == keyboard.enter) { slider.value=number(textin.text); } } if prefer use addeventlistener should it:
textin.addeventlistener(keyboardevent.key_down, textin_keydownhandler);
Comments
Post a Comment