Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Slider controlled position array

  • Slider controlled position array

    Posted by Connor Roberts on January 27, 2025 at 10:55 pm

    Hey friends,

    I need some help ironing out a position expression. Essentially, I have a slider that runs 1-5. I have a set yPosition key for each slider number within the object (if the slider is 5, then the position of the object is 2.8 (key 2), for example). I’ve tried to set this up as an array, but I keep getting errors (mostly undefined value used in expression). Just want to know if I am going about this the wrong way, or if I am messing up the code somewhere… I don’t need the object to animate to the new position, just jump to where it needs to be.

    Here is my stab at this:

    transform.yPosition

    var p1 = transform.yPosition.key(1);

    var p2 = transform.yPosition.key(2);

    var p3 = transform.yPosition.key(3);

    var p4 = transform.yPosition.key(4);

    var p5 = transform.yPosition.key(5);

    var a = Array(p1,p2,p3,p4,p5);

    var r = thisComp.layer(“[+] moveAmtE”).effect(“moveAmtE”)(“Slider”);

    a[r]

    I have gotten something similar to work for changing the path of a shape, though it was set to random instead of a slider, this is below:

    var k1 = content(“Rectangle 1”).content(“path1”).path.key(1)

    var k1 = content(“Rectangle 1”).content(“path1”).path.key(2)

    var a = Array(k1,k2);

    var r = Math.floor(random(0,4));

    a[r]

     

    I appreciate any help offered!

     

    Cheers,

     

    Connor

    Dan Ebberts
    replied 2 weeks, 6 days ago
    2 Members · 2 Replies
  • 2 Replies
  • Connor Roberts

    January 27, 2025 at 11:12 pm

    Just an update,

    I did manage to solve this during the time it took to post. I used a series if/else statements instead:

    if(thisComp.layer(“[+] moveAmt”).effect(“moveAmtN”)(“Slider”) ==1) transform.yPosition.key(1)

    else if(thisComp.layer(“[+] moveAmt”).effect(“moveAmtN”)(“Slider”) ==2) transform.yPosition.key(2)

    else if(thisComp.layer(“[+] moveAmt”).effect(“moveAmtN”)(“Slider”) ==3) transform.yPosition.key(3)

    else if(thisComp.layer(“[+] moveAmt”).effect(“moveAmtN”)(“Slider”) ==4) transform.yPosition.key(4)

    else if(thisComp.layer(“[+] moveAmt”).effect(“moveAmtN”)(“Slider”) ==5) transform.yPosition.key(5)

    else transform.yPosition.key(1);

    however, curious if anyone does figure out how to do this in an array!

  • Dan Ebberts

    January 27, 2025 at 11:26 pm

    If I’m understanding what you’re trying to do, I think you want something like this:

    s = effect("moveAmtN")("Slider");
    n = clamp(Math.round(s),1,numKeys);
    valueAtTime(key(n).time)

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