beautypg.com

Add comments to an expression, Save and reuse expressions – Adobe After Effects CS4 User Manual

Page 658

background image

652

USING AFTER EFFECTS CS4

Expressions

Last updated 12/21/2009

thisComp.layer(index + 1).name + "\rOpacity = " + thisComp.layer(index + 1).opacity.value

The following example reports the name of the footage item used as the source of the topmost image layer in the
stacking order at the current time that has its Video switch set.

source_footage_name = "";
for (i = 1; i <= thisComp.numLayers; i++){
if (i == index) continue;
my_layer = thisComp.layer(i);
if (! (my_layer.hasVideo && my_layer.active)) continue;
if (time >= my_layer.inPoint && time < my_layer.outPoint){
try{
source_footage_name = my_layer.source.name;
}catch(err1){
source_footage_name = my_layer.name
}
break;
}
}
source_footage_name

Aharon Rabinowitz provides a video tutorial and example expressions on

Red Giant TV

that show how to animate a

video game score with the Source Text property and a Slider effect (an Expression Controls effect).

More Help topics

Creating and editing text layers

” on page 341

Add comments to an expression

If you write a complex expression and intend for you or someone else to use it later, you should add comments that
explain what the expression does and how its pieces work.

Type

//

at the beginning of the comment. Any text between

//

and the end of the line is ignored. For example:

// This is a comment.

For examples of this type of comment, see

Expression example: Fade opacity of a 3D layer based on distance from

camera

” on page 685.

Type

/*

at the beginning of the comment and

*/

at the end of the comment. Any text between

/*

and

*/

is ignored.

For example:

/*

This is a

multiline comment. */

For examples of this type of comment, see

Save and reuse expressions

” on page 652.

Save and reuse expressions

Once you have written an expression, you can save it for future use by copying and pasting it into a text-editing
application or by saving it in an animation preset or template project. However, because expressions are written in
relation to other layers in a project and may use specific layer names, you must sometimes modify an expression to
transfer it between projects.

You can define your own functions within expressions using normal JavaScript function syntax. In this example, a
function is defined that calculates the average of two values, and the last line uses this function:

This manual is related to the following products: