-
Slider and EditText binded with atChange, live update?
Hi! I’m working with a script where the user can ether user a slider or write in an EditText-field.
Everything is working perfect but I would love if the slider and EditText could update live, directly.
What I mean is if I slide the slider I want the numbers to update in real time in the EditText-box and if I write a number in the EditText-box I want the slider to jump to the correct possition directly.Right now the EditText only updates when I release the slider and the slider only updates when I press outside the EditText-box.
This is the part of my script:
var my_palette = (thisObj instanceof Panel) ? thisObj : new Window("palette", scriptName, undefined, {resizeable:true});
if (my_palette != null)
{
var res =
"group {
orientation:'column', alignment:['fill','top'], alignChildren:['left','top'], spacing:5, margins:[0,0,0,0],
strt: Group {
alignment:['fill','top'],
startButton: Button { text:'Apply Linear Wipe', alignment:['fill','center'] },
},
optsRow: Panel{text:'Cut at:',
orientation:'column', alignment:['fill','top'],
mySlider: Slider { text:'my slider', value:'50', alignment:['fill','center']},
text_input: EditText { text:'50', alignment:['fill','top'], preferredSize:[100,20] },
},
cmds: Group {
alignment:['fill','top'],
okButton: Button { text:'Cut!', alignment:['fill','center'] },
},
}";// Set the callback. When the user enters text, this will be called.
my_palette.grp.optsRow.text_input.onChange = on_textInput_changed;
my_palette.grp.optsRow.mySlider.onChange = mySlider_changed;//
// This function is called when the user enters text for the scale.
//
function on_textInput_changed()
{
// Set the scale_factor based on the text.
var value = this.text;
if (isNaN(value)) {
alert(value + " is not a number. Please enter a number.", scriptName);
} else {
my_palette.grp.optsRow.mySlider.value = Math.round(value);
transition.property("ADBE Linear Wipe-0001").setValue(value);
scale_factor = value/100;
}
}//
// This function is called when the user slides the scale.
//
function mySlider_changed()
{
// Set the scale_factor based on the text.
var value = this.value;
if (isNaN(value)) {
alert(value + " is not a number. Please enter a number.", scriptName);
} else {
my_palette.grp.optsRow.text_input.text = Math.round(value);
transition.property("ADBE Linear Wipe-0001").setValue(value);
scale_factor = value/100;
}
}Thanks!