Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Activate/DeActivate A parent using a checkbox

  • Activate/DeActivate A parent using a checkbox

    Posted by Max Souliers on March 18, 2025 at 2:21 pm

    Hi AE Expression Wizards! I’m looking for an expression to use a “checkbox” to activate and/or deactivate a parent. For example, I separated the X and Y positions on the Parent layer AND on the child layer. Then, I put a checkbox control on my child layer. And I wanted to add an expression on the X and/or the Y position to parent the child layer position to the parent layer position only when I check the checkbox. Otherwise, my child doesn’t follow the parent. Could you help me??? Thank You in advance.

    Dan Ebberts replied 1 month, 1 week ago 3 Members · 2 Replies
  • 2 Replies
  • Roland R. kahlenberg

    March 18, 2025 at 7:13 pm

    See if this works – take note that it doesn’t account for keyframing the checkbox which will result in position jumping –

    for xPosition –

    if (effect(“Checkbox Control”)(“Checkbox”) == 1 || thisLayer.parent == null) {

    // When checked or no parent, use normal/parented position value

    value;

    } else {

    // When unchecked, counteract parent’s position

    parentLayer = thisLayer.parent;

    // Get parent’s world position at current time

    parentWorldPos = parentLayer.toWorld([0,0]);

    // Get parent’s world position at time 0 (initial position)

    parentWorldPosT0 = parentLayer.toWorld([0,0], 0);

    // Calculate parent’s position change

    parentDeltaX = parentWorldPos[0] – parentWorldPosT0[0];

    // Subtract parent’s movement from our current position

    value – parentDeltaX;

    }

    for yPosition –

    if (effect(“Checkbox Control”)(“Checkbox”) == 1 || thisLayer.parent == null) {

    // When checked or no parent, use normal/parented position value

    value;

    } else {

    // When unchecked, counteract parent’s position

    parentLayer = thisLayer.parent;

    parentWorldPos = parentLayer.toWorld([0,0]);

    parentWorldPosT0 = parentLayer.toWorld([0,0], 0);

    parentDeltaY = parentWorldPos[1] – parentWorldPosT0[1];

    value – parentDeltaY;

    }

  • Dan Ebberts

    March 18, 2025 at 7:17 pm

    This may not be what you’re after, as it requires the checkbox to be keyframed to on when you want the child’s x position to follow changes in the parent’s x position:

    p = thisComp.layer("parent").transform.xPosition;
    cb = effect("Checkbox Control")("Checkbox");
    accum = value-value;
    if (cb.numKeys > 0){
    n = 0;
    n = cb.nearestKey(time).index;
    if (cb.key(n).time > time) n--;
    if (n > 1){
    if (cb.key(n).value) accum += p - p.valueAtTime(cb.key(n).time);
    for (i = n-1; i > 0; i--){
    if (cb.key(i).value) accum += p.valueAtTime(cb.key(i+1).time) - p.valueAtTime(cb.key(i).time);
    }
    if (cb.key(1).value) accum += p.valueAtTime(cb.key(1).time) - p.valueAtTime(0);
    }
    }else{
    if (cb.value) accum = p - p.valueAtTime(0);
    }
    value + accum

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