Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Continuous linear movement that starts and stops on a checkbox

  • Continuous linear movement that starts and stops on a checkbox

    Posted by James Ronan on March 13, 2019 at 9:12 am

    Hey all

    I’ve got an object continuously move along one axis at a rate of 5px per frame.

    What I’d like to do is set up a check box that when checked, starts and stops the movement. Keeping the object in the same position until it’s checked again.
    So far any attempt I’ve had resets the objects position to 0 when checkbox is false;


    var pos = 0;
    var check = effect("Checkbox Control")("Checkbox");
    var frames = timeToFrames(time,25)
    var speed = 5;

    for (var i = 0; i < (frames); i++){
    if (check == 1){
    pos += speed;
    }
    }

    pos;

    Any help would be awesome!

    Thanks!

    Alex Printz replied 7 years, 2 months ago 2 Members · 3 Replies
  • 3 Replies
  • Alex Printz

    March 13, 2019 at 1:56 pm

    You were really close, you just need to check if the checkbox controller is active at that specific frame:

    var pos = 0;
    var check = effect("Checkbox Control")("Checkbox");
    var frames = timeToFrames(time,25)
    var speed = 5;

    for (var i = 0; i < (frames); i++){
    if (check.valueAtTime(framesToTime(i)) == 1){
    pos += speed;
    }
    }

    [pos,0];

    Also, I think you can drop your timeToFrames FPS property (25), unless specific, the function will default to the comp framerate.

    Alex Printz
    Mograph Designer

  • James Ronan

    March 14, 2019 at 3:10 pm

    Ah thanks for the reply Alex! That makes more sense!

    So it’s still not working working for me unfortunately. It works in a text layer… I can see it counting up.

    But when used on a position property, rotation etc. it still doesn’t work and only shows the initial value written at the start.

    Any idea why? Thanks again!!!

    James

  • Alex Printz

    March 15, 2019 at 2:41 pm

    Are you sure that it is not working for you? I just copy+paste’d my code into a shapelayer’s position and rotation, and it worked fine in both of those. Are you getting any sort of error?

    Alex Printz
    Mograph Designer

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