Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Slider and EditText binded with atChange, live update?

  • Slider and EditText binded with atChange, live update?

    Posted by Jacob Danell on July 22, 2013 at 5:00 pm

    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!

    Dan Ebberts replied 12 years, 10 months ago 2 Members · 6 Replies
  • 6 Replies
  • Dan Ebberts

    July 22, 2013 at 5:35 pm

    You should try onChanging instead of onChange.

    Dan

  • Jacob Danell

    July 22, 2013 at 5:55 pm

    It was that simple huh…. Sometimes you really feel stupid.
    Well an other problem that came up now is that I have the value linked to a Linear Wipe-effekt too but if I want to undo the whole script process I have like a hundred of undos because of every value-change of the script. I know you use app.beginUndoGroup for these things but when I possition it in the function it doesn’t help, probebly because the function is ran every time the value changes. Where should I possition app.beginUndoGroup for it to work?

  • Dan Ebberts

    July 22, 2013 at 5:58 pm

    I generally put it right before the first thing the script does that changes something in the project. So it would probably be upstream from your function call.

    Dan

  • Jacob Danell

    July 22, 2013 at 7:54 pm

    I tried to apply it on the top of all but it didn’t work.
    I think the problem is that when I use “onChanging” it will apply a new action that After Effects make an undo to.
    When I used “onChange” a new undo was created every time I undid or wrote a new number, now it changes all the time. Is there anyway to collect all changes into one undo?

  • Dan Ebberts

    July 22, 2013 at 8:02 pm

    Where do you have the endUndoGroup() ?

  • Dan Ebberts

    July 22, 2013 at 8:06 pm

    Off hand, I can’t think of a way to collect all the actions of your onChanging() routine into one undo group. You might have to choose between live update and an overall undo group. Or maybe you use an onChanging() routine to do the update of the UI, and use onChange() to change the effect parameter. There has to be a way.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy