ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Global variables for expressions.

COW Forums : Adobe After Effects

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Michael TammaroGlobal variables for expressions.
by on Aug 12, 2014 at 9:23:41 pm

Consider the following two expressions, which might be applied to two different layers:

(1) x = A*Math.cos(6*time); y = 600; [x,y]

(2) x = A*Math.cos(12*time); y = 600; [x,y]

Is there a way to set the value of A globally, so that I don't have to exit each expression every time I change A?


Return to posts index

John CuevasRe: Global variables for expressions.
by on Aug 13, 2014 at 1:33:35 am

Make "A" a variable that's linked to a slider on a control null layer.

Null layer named "Control":

A = thisComp.layer("Control").effect("Slider Control")("Slider");
x = A*Math.cos(12*time); y = 600; [x,y]


Johnny Cuevas, Editor
Thinkck.com

"I have not failed 700 times. I have succeeded in proving that those 700 ways will not work. When I have eliminated the ways that will not work, I will find the way that will work."
---THOMAS EDISON on inventing the light bulb.


Return to posts index

Michael TammaroRe: Global variables for expressions.
by on Aug 13, 2014 at 6:17:52 pm

Johnny, thank you!

If I have, say, 5 variables, do I need to create five null layers--one for each variable?


Return to posts index


John CuevasRe: Global variables for expressions.
by on Aug 13, 2014 at 7:23:21 pm
Last Edited By John Cuevas on Aug 13, 2014 at 7:24:01 pm

You could put all the sliders on one Null control layer. When I made that A variable, I just picked whipped to it, but each expression slider will have a different name "slider" "slider 2"...so you could type it in if you wanted, just need to get the naming correct.

Also you can rename the slider Control itself if that will make things easier, for instance, you could rename your slider control--position control and your expression would look like:

A = thisComp.layer("Control").effect("position control")("Slider");

Hope that helps you out, I only know the basics of expressions.

Johnny Cuevas, Editor
Thinkck.com

"I have not failed 700 times. I have succeeded in proving that those 700 ways will not work. When I have eliminated the ways that will not work, I will find the way that will work."
---THOMAS EDISON on inventing the light bulb.


Return to posts index

Michael TammaroRe: Global variables for expressions.
by on Aug 13, 2014 at 8:07:04 pm

Excellent. Thanks.

Sorry to be so needy, but I'm getting a syntax error in the following expression:

x0 = 865; y0 = 525; r1 = Math.sqrt((745 – x0)*(745 – x0) + (660 – y0)*(660 – y0)); r2 = Math.sqrt((895 – x0)*(895 – x0) + (660 – y0)*(660 – y0)); o1 = thisComp.layer("on1").effect("Slider Control")("Slider"); o2 = thisComp.layer("on2").effect("Slider Control")("Slider”); l = thisComp.layer("Wavel").effect("Slider Control")("Slider"); f = thisComp.layer("Freq").effect("Slider Control")("Slider"); A = thisComp.layer("Amp").effect("Slider Control")("Slider"); s1 = o1*A*Math.cos(2*Math.PI*r1/l – 2*Math.PI*f*time); s2 = o2*A*Math.cos(2*Math.PI*r1/l – 2*Math.PI*f*time); st1 = (x0 – 745)/r1; ct1 = (660 – y0)/r1; st2 = (x0 – 895)/r1; ct1 = (660 – y0)/r2; x = s1*st1 + s2*st2; y = s1*ct1 + s2*ct2; [x,y]


Return to posts index

Michael TammaroRe: Global variables for expressions.
by on Aug 13, 2014 at 8:41:36 pm

It has something to do with the square root, because I'm getting an error with this one too:

x0 = 1; y0 = 2; r1 = Math.sqrt((745 – x0)*(745 – x0) + (660 – y0)*(660 – y0)); x = r1 + x0; y =r1 + y0; [x,y]


Return to posts index


John CuevasRe: Global variables for expressions.
by on Aug 14, 2014 at 2:27:20 am

At this point, I'm out of my depth, so I'm going to refer you to the Expressions Forum, the guys there are a lot more experienced than me.

Johnny Cuevas, Editor
Thinkck.com

"I have not failed 700 times. I have succeeded in proving that those 700 ways will not work. When I have eliminated the ways that will not work, I will find the way that will work."
---THOMAS EDISON on inventing the light bulb.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]