CONTENTS Introduction When to Use Expressions What Is an Expression? Adding Expressions The Pick Whip Vectors and Dimensions Ranges of Values Interpolation Methods Objects Global Objects The Default Object Methods and Attributes Vector Math an example OTHER MATERIAL Geometry HOME What Is an Expression? An expression is a statement that produces values for a specific parameter. The simplest expression would be just a number: 6; Obviously, this kind of expression isn’t very useful — you’d be much better off just setting the parameter to 6 directly. A slightly more useful expression would be something like: rotation; When evaluated, this statement will return the value of rotation for the current layer at the current time. This return value, or result, will then be used for whatever parameter the expression is attached to. If applied to a layer’s opacity parameter, this expression would make the layer’s opacity change in sync with its rotation: when the rotation was 30 degrees, the opacity would be set to 30%, etc.. Expressions use the JavaScript language and syntax (an industry-standard language commonly used for web development, and for which there are many helpful books). Javascript includes a rich set of tools for creating more complex expressions, including, of course, the basic math operations: opacity*10; This expression is slightly more sophisticated, but still very simple. Its result is the value of opacity for the current layer at the current time, multiplied by ten. Since opacity has a range of zero to 100, the results of this expression will range from zero to 1,000. These results will be used for whatever parameter to which you've applied the expression. Where's the '='? You may expect expressions to look something like, "position=rotation". Well, they don't. Expressions don't need to explicitly assign their results to a parameter, so they don't use equals sign (AKA 'assignment operator') in this way. This kind of assignment is implicit. An expression supplies values for the parameter to which it is attached. So, the 'position=' part of the expression is simply assumed by the fact that it is attached to your layer's position parameter, for instance. Of course, you certainly can use the equals sign in your expressions, for instance to assign values to variables. You just don't need to start (or end) your expressions with a 'parameter='. One Expression, One Parameter A consequence of this is that a single expression can control only one parameter. That is, because each expression is attached to just a single parameter, it can supply values for only that parameter. You could not, for instance, create a single expression that would modify both a layer’s position and its rotation; you would need to create two distinct expressions, one attached to position and the other attached to rotation. Multi-line Expressions Expressions can be more than one line. In fact, they could run to several hundred lines. It’s a good idea to keep them short, however, as that will make them easier to follow, and probably quicker to execute as well. When an expression contains more than one line, its result will be the value of the last line evaluated. For instance, the value of the following expression: offset=30; ralph=rotation+offset; ralph; will be the value of ‘ralph’, which would be the layer’s current rotation plus 30 degrees, viz: By the way, notice that each line of these expressions ends in a semicolon. You must end every line with a semicolon, so that After Effects knows where one line ends and the next begins. Consider it the equivalent of a period in English. Technically, the last line doesn’t need a semicolon, but because it doesn’t hurt, I always put a semicolon there as well.   Adding Expressions to Your Project There are two easy ways to add an expression to a selected parameter. You could select the parameter in the Timeline, and then choose "Add Expression" from the Animation menu. It’s easier, though, to simply option-click (Alt-click on Windows) the stopwatch icon next to the parameter name in the Timeline. You’ll notice that you now have a few new elements in the Timeline: First, there is a button with an equals sign (‘=’) to the left of the parameter name — click this to temporarily disable or re-enable this expression. Second, the parameter’s value has turned red, indicating that it is driven by an expression and can no longer be directly edited. Third, there is a short row of three icons to the right of the parameter name, which we discuss below. Finally, there is the expressions text-edit field, where your expression lives and can be edited. Notice that you can pull down the bottom of this area if you need more room for multi-line expressions. The first button will twirl down a graph of your expression’s results in the Timeline. If your expression affects an element’s motion path, this will also change the way the path is displayed in the Comp window, to display the post-expression results. The second button is the Pick Whip, a tool that can help you write basic expressions. Simply drag the whip to another parameter, and After Effects will create a live link, driving the current parameter with values from the whip's target. I discuss the Pick Whip in greater detail in the next section. The third is the Expressions language pop up menu. This menu is a handy reference to all of the After Effects-specific features in the Expression language. You can use this menu to quickly see what objects and attributes are available to you.

Entire contents © 2001 JJ Gifford.