Activity › Forums › Adobe After Effects Expressions › Slider expression
-
David Conklin
November 25, 2014 at 3:35 pmthe [0] part (as in cntrl[0] or position[0]) is what’s picking out the X values. The position parameter is actually an array with 3 positions [x, y, z]. Since in javascript the first index of an array is 0, the values 0, 1 and 2 correspond to X, Y and Z respectively.
so,
position[0] = X Position
position[1] = Y Position
position[2] = Z PositionSimply change any/all [0]s to [1]s in order to use Y instead of X.
David Conklin
Motion Designer -
Ryan Biercewicz
November 26, 2014 at 1:46 pmHi David,
Sorry to say but I can’t figure out how to modify the expression so that it will run, say, from left to right, or down to up (so, in reverse)?
Cheers
Ryan -
Ryan Biercewicz
November 26, 2014 at 5:12 pmHi David,
Sorry to keep bothering you with this! I’m finding I need to adapt the expression as I move through the project, and my skills with expressions are fairly basic.
My next problem is that some of my boxes have 4 key frames on them – so a move in, and a move out. I’d like each counter to settle on its final number (11.1111) on the 2nd keyframe, then continue to move on the 3rd and finish at another number on the 4th.
I got as far as modifying the cntrl.key(1), cntrl.key(2), (3) as I’m guessing these correspond to each keyframe in the sequence, but I guess I need to add a ‘start and stop’ to the slider / box move?
This would also resolve my last question, so if this can be done then please ignore that one!
Cheers
Ryan -
David Conklin
November 26, 2014 at 7:32 pmHey Ryan,
I’m having a hard time following what you’re going for this time, but here’s what I’ve got. Hopefully it will put you on the right track:
This expression will go from 0 to 11.111 during the time between keyframes 1 and 2, hold at 11.111 between keyframe 2 and 3, and then go from 11.111 to 50 between keyframe 3 and 4. Of course, 50 is an arbitrary number I made up, so feel free to change it.
This expression now is not ‘mapping’ the position of your box to this slider, but rather creating slider values that correspond w/ the time of your keyframes. Meaning, the slider value is 0 up until the first keyframe, regardless of where the box is on screen (same for all other slider values).
Let me know if this works, otherwise perhaps you could give me a little more detail on what you’re trying to accomplish.
Good luck,
//this goes on the slider
//change this to the layer of your box
var cntrl = thisComp.layer(“BOX”);//this is the property we’re tracking
var getProp = cntrl.transform.position;//set slider values
var valAtStart = 0; //keyframe 1
var valAtHold = 11.111; //keyframe 2 + 3
var valAtEnd = 50; //keyframe 4.//make sure we have at least 4 keyframes.
if(getProp.numKeys >= 4){//get time of keyframes
var key1Time = getProp.key(1).time;
var key2Time = getProp.key(2).time;
var key3Time = getProp.key(3).time;
var key4Time = getProp.key(4).time;//make animations
var animOn = ease(time, key1Time, key2Time, valAtStart, valAtHold);
var animOff = ease(time, key3Time, key4Time, valAtHold, valAtEnd);//apply animation
if (time < key1Time){ valAtStart; } else if (time < key2Time){ animOn; } else if (time < key3Time){ valAtHold; } else if (time < key4Time){ animOff; } else { valAtEnd; } } else { //just use slider value if there's less //than 4 keyframes. This will prevent //error dialog spam if you delete //keyframes. value; } David Conklin Motion Designer -
Ryan Biercewicz
November 27, 2014 at 9:40 amHi David,
Apologies for the confusion! But, this is fantastic, exactly what I’m after. It gives me a lot more control over the counter numbers which I need for my project.
Thanks again for taking the time to do this…
Best,
Ryan
Reply to this Discussion! Login or Sign Up