Monday 28 January 2013

Linking an Effect Parameter to a Property


Linking an Effect Parameter to a Property

Here’s the scenario: You want to link an effect to an audio
track. Specifi cally, you want to link the Field Of View
(FOV) parameter of the Optics Compensation effect to
the amplitude of an audio layer. Expressions can’t access
audio levels directly, so fi rst you have to use a keyframe
assistant (Animation > Keyframe Assistant > Convert Audio
to Keyframes) to create a null layer named Audio Amplitude
with Slider Controls keyframed for the audio levels of
the Left, Right, and Both channels (for a stereo source).

Next, you just Alt/Option-click the stopwatch for the FOV
parameter of the Optics Compensation effect and drag
the pickwhip to the Both Channels Slider property of the
Audio Amplitude layer. Doing so generates
this expression
thisComp.layer("Audio Amplitude").effect("Both
➥Channels")("Slider")
Take a closer look at its syntax: From JavaScript, the
After Effects expression language inherits a left-to-right
“dot” notation used to separate objects and attributes in
a hierarchy. If your expression references a property in a
different layer, you fi rst have to identify the composition.
You can use thisComp if the other layer happens to be in
the same composition (as in this example). Otherwise,
you would use comp("other comp name"), with the other
composition name in quotes. Next you identify the layer
using layer("layer name") and fi nally, the property, such
as effect("effect name")("property name") or possibly
transform.rotation.
In addition to objects and properties, the dot notation
hierarchy can include references to an object’s attributes
and methods. An attribute is just what you would guess: a
property of an object, such as a layer’s height or a composition’s
duration. In fact, in JavaScript documentation, attributes
are actually referred to as properties, but in order to
avoid confusion with the layer properties such as Position
and Rotation (which existed long before expressions came
along), in After Effects documentation (and here) they’re
referred to as attributes. For example, each layer has a
height attribute that can be referenced this way:
comp("Comp 1").layer("Layer 1").height

Methods are a little harder to grasp. Just think of them
as actions or functions associated with an object. You can
tell the difference between attributes and methods by the
parentheses that follow a method. The parentheses may
enclose some comma-separated parameters.
It’s important to note that you don’t have to specify the full
path in the dot notation hierarchy if you’re referencing
attributes or properties of the layer where the expression
resides. If you leave out the comp and layer references,
After Effects assumes you mean the layer with the expression.
So, for example, if you specify only width, After
Effects assumes you mean the width of the layer, not the
width of the composition.
Let’s forge ahead. You linked the amplitude of your audio
layer to your effect parameter, but suppose you want to
increase the effect that the audio level has on the parameter.
You can use a little JavaScript math to multiply the
value by some amount, like this
thisComp.layer("Audio Amplitude").effect("Both
➥Channels")("Slider") * 3
Towards the end of the chapter you’ll see a much more
complicated and powerful way of linking an effect to audio.


No comments:

Post a Comment