Conditionals


Also known as If/Then statements, conditionals open up a host of possibilities. They allow you to use any circumstance that expressions can recognizepretty much any numerical or Boolean condition in the timelineas a condition for an event or a series of events to occur.

If you're really going to harness the power of automation in expressions, it's extremely helpful to understand how to set up conditionals. All kinds of effects shots feature a cause-and-effect relationship that you can set up logically with expressions so that, even if the timing or other parameters change, the amount of busywork involved in rippling those changes through is minimized.

Triggering a Filmic Dissolve

Here's a simple example of conditionals: using layer markers to trigger a one-second filmic dissolve. This expression could just as easily be set up to trigger a different operation, such as a simple opacity fade to black or white, but once you understand the basics, you'll be able to adapt it however you like.

A composition marker can be set by pressing Shift+1 (or Shift plus any number, 0 through 9, on the top of the keyboardnot the numeric keypad). For the following example to work as-is, if you want to try it yourself, place marker number 1 (Shift+1) at the frame at which you want the fade to begin.

Add the Levels (Individual Controls) effect. Reveal controls for Input Black and Output White; you'll be applying the same expression to each, with the variation that they will be animated in opposition (Figure 10.18). The expression for Input Black is

 mark = thisComp.marker(1); linear(time, mark, mark+1, 0, 1) 

Figure 10.18. The expressions have been set for Input Black and Output White; values appear in red in the Timeline and Effect Controls windows.


The inversion for Output White is

 mark = thisComp.marker(1); linear(time, mark, mark+1, 1, 0) 

You can apply an expression directly from the Effect Controls window by Alt-clicking (Option-clicking) on the stopwatch, the same way you would in the Timeline window. This can be convenient because the property with the expression is revealed in the timeline as well, where you can edit the expression.


What the heck? Here's what's happening. This is the first example in this chapter in which you're setting a variable. This one is called mark, named for the fact that it identifies a marker (and also for the author's vanity). How do you know it's a marker and which one it is? The variable's argument tells you; the thisComp.marker portion signifies a marker and (1) specifies which one. Any time you use a unique name followed by an equals sign, you are telling After Effects to save you the trouble of having to repeatedly type whatever comes after that equals sign. That's all. No big deal about variables.

The linear(t, tMin, tMax, value1, value2) command is so compact and efficient that it's easy to forget it even exists. It has five (count 'em) required arguments that identify, in order, the

  • Time that the effect evaluates

  • Time to start a linear transition

  • Time to end a linear transition

  • Value at the start

  • Value at the end

With this in mind, you can see that the expression first evaluates the current time (time). When that time reaches mark (marker 1), After Effects should perform a linear transition from 0 (0%) to 1 (100%), and the transition should last one second (until mark + 1, or one second past marker 1). You can see what's going on in the expressions graphs, and the result is reflected in the Composition window (Figure 10.19).

Figure 10.19. The result of the dissolve appears in the graphs as well as in the composition itself. A filmic dissolve re-creates what happens to film densities when film is faded to black.


Now, why go to all that trouble to do an effect that would take a few keyframes? Because you can save the effect into your favorites and apply it whenever you want to trigger a filmic dissolve using a layer marker, without having to do any keyframing or setup at all, and you can change this animation, which would require four keyframes, using only the marker. Not life-changing, perhaps, but satisfying and one more indication of the many applications of expressions.

How will you ever remember how to do this again? Most of the components of this expression are organized into the Expressions menu. A variable is always set by naming it and then adding = after the name; whatever follows the equals sign is the variable setting. (There's no need to type variables in JavaScript, in case you were wondering about that.) The shorthand thisComp is in the Global category of the menu, which also tells you that it sits at the top level of any hierarchy, such as thisComp.marker(1). Look in the Comp category for marker(name); you need to add the dot separation between them and the semi-colon at the end yourself. As you've seen already, these are basics of JavaScript. With all of its defaults, linear() is an interpolation function and found in the Interpolation category. (You'll see two versions there, one showing the option of fewer arguments).



Adobe After Effects 6. 5 Studio Techniques
Adobe After Effects 6.5 Studio Techniques
ISBN: 0321316207
EAN: 2147483647
Year: 2006
Pages: 156

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net