After Effects CS3  |  Go to CS4 Help

Example: Use the expression language reference to write an expression

Follow along with this example to learn how to use the After Effects expression language reference to write expressions. The expression created in this example copies position values from one layer to another.

  1. Create two solid layers: Solid 1 and Solid 2.

  2. Animate the Position property values for Solid 1 using keyframes. (See About animation, keyframes, and expressions.)

  3. Select the Position property for Solid 2 and choose Animation > Add Expression or Alt-click (Windows) or Option-click the property’s stopwatch button. The following expression appears by default:

      transform.position
  4. Type the following directly over transform.position:

      thisComp
  5. The element thisComp is a global attribute whose value is a Comp object representing the current composition. To determine what can follow thisComp in your expression, look up the return value for thisComp under Global objects.

    Note that thisComp returns a Comp. Next, look at Comp attributes and methods to see which attributes and methods you can use with a Comp. One option is layer(index). The index, or number, inside the parentheses specifies the layer that you want to use. For this example, we assume that Solid 1 is the first layer in your composition. To retrieve values from the first layer in the active composition, type .layer(1) at the end of the expression, to get the following:

      thisComp.layer(1)
  6. Again, look at the expression elements reference to see that layer(index) returns a Layer. Look at Layer General attributes and methods, and find the element you want to use. For example, if you want to access the Position property’s values for the layer, type .position at the end of the expression to get the following:

      thisComp.layer(1).position 
  7. From Layer General attributes and methods, you can see that the position attribute returns a property. Look up Property attributes and methods and notice that you can add a time factor to the expression. To add a specific time, such as current time plus 2 seconds, type .valueAtTime(time+2)at the end of the expression to get the following:

      thisComp.layer(1).position.valueAtTime(time+2)
  8. From Property attributes and methods, notice that the valueAtTime method returns a number or Array. When an expression returns a Number, Array, or Boolean (true or false), you cannot add further attributes or methods to the expression (if you want, however, you can add arithmetic operators, such as +, -, *, and /).




Comments

Comments are no longer accepted for After Effects CS3. After Effects CS4 is the current version. To discuss After Effects CS3, please use the Adobe forum.

 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/en_US/AfterEffects/8.0/WS3878526689cb91655866c1103906c6dea-7a27.html