programming4us
 
Graphics
 

Adobe After Effects CS5 : Expressions - Using a Layer’s Index

5/30/2013 9:09:06 PM

A layer’s index attribute can be used as a simple but powerful tool that allows you to create expressions that behave differently depending on where the layer is situated in the layer stack. The index attribute corresponds exactly to the number assigned to the layer in the Timeline window. So, the index for the layer at the top of the stack is 1, and so on.

Time Delay Based on Layer Index

Suppose you keyframed an animation for one layer. Now you want to create a bunch of identical layers, but you want their animations to be delayed by an amount that increases as you move down the layer stack. You also want to rotate each copy by an amount proportional to its position in the layer stack. To do so, you first apply an expression like this to the top layer’s animated properties:

delay = 0.15;
valueAtTime(time - (index-1)*delay)

Then you apply an expression like this to the Rotation property:

offsetAngle = 3;
value +(index-1)*offsetAngle

Finally, duplicate the layer a bunch of times. The animation of each layer will lag behind the layer above it by 0.15 seconds and the rotation of each layer will be 3 degrees more than the layer above (Figure 1).

Figure 1. Notice how the blaster shot created by each layer lags that of the previous layer and is at a slightly different angle.


What’s going on here? In the first expression, the first line defines a JavaScript variable named delay and sets its value to 0.15 seconds. The second line is where all the action is, and it’s packed with new things. For example, notice the use of time. It represents the current composition time, in seconds. In other words, time represents the time at which the expression is currently being evaluated.

You use valueAtTime() to access a property’s pre-expression value at some time other than the current comp time (to access the pre-expression value at the current comp time, use value() instead, as in the Rotation expression). The parameter passed to valueAtTime() determines that time:

time – (index-1)*delay

Subtracting 1 from the layer’s index and multiplying that result by the value of the delay variable (0.15) gives the total delay (in seconds) for this layer. Subtracting 1 from index means that the delay will be 0 for the first layer. So, for Layer 1, the total delay is 0, for Layer 2 it is 0.15, for Layer 3 it is 0.30, and so on. You then subtract the total delay from the current comp time. The result of this is that Layer 1’s animation runs as normal (not delayed). Layer 2’s animation lags behind Layer 1 by 0.15 seconds, and so on.

Tip

Remember, if you don’t specify a comp and layer when referencing a property or attribute, After Effects assumes you mean the layer with the expression. When you reference an attribute of the property housing the expression, After Effects makes a similar assumption, allowing you to specify only the attribute name (without the entire comp/layer/property path). One side benefit of not having to specify the entire path is that you can apply the same expression to any property, without having to modify it at all.


The Rotation expression is very similar except that it doesn’t reference time. The reason for this is that the first expression is used to offset a keyframed animation in time, while the second expression simply creates a static (not animated) offset for the Rotation property. The first line of the expression defines a variable named offsetAngle. This variable defines the rotation amount (in degrees) by which each layer will be offset from the layer above it. The second line tells After Effects to calculate the layer’s offset and add it to the pre-expression value of the property.

You’ll see other ways to use index in later examples.

 
Others
 
- Adobe After Effects CS5 : Expressions - Linking an Effect Parameter to a Property
- Adobe Fireworks CS5 : Working with Vector Graphics - Customizing fills and strokes (part 4) - Adding to the skyline, Adding windows to the building
- Adobe Fireworks CS5 : Working with Vector Graphics - Customizing fills and strokes (part 3) - Using the Compound Shape tool, Working with compound shapes
- Adobe Fireworks CS5 : Working with Vector Graphics - Customizing fills and strokes (part 2) - Customizing the stroke, Importing and resizing a vector object
- Adobe Fireworks CS5 : Working with Vector Graphics - Customizing fills and strokes (part 1) - Adding a gradient fill
- Adobe Flash Professional CS5 : Working Within the Flash Environment - Setting General Preferences
- Adobe Flash Professional CS5 : Working Within the Flash Environment - Creating Keyboard Shortcuts
- Adobe Flash Professional CS5 : Working Within the Flash Environment - Creating a Workspace
- Adobe InDesign CS5 : Working with Objects and Layers - Repeating Object Transformations
- Adobe InDesign CS5 : Working with Objects and Layers - Arranging Object Stack Order, Transforming Objects
 
 
REVIEW
 
- First look: Apple Watch

- 10 Amazing Tools You Should Be Using with Dropbox

- Sigma 24mm f/1.4 DG HSM Art

- Canon EF11-24mm f/4L USM

- Creative Sound Blaster Roar 2

- Alienware 17 - Dell's Alienware laptops

- Smartwatch : Wellograph

- Xiaomi Redmi 2
 
VIDEO TUTORIAL
 
- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 1)

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 2)

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 3)
 
Popular tags
 
Video Tutorail Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8 BlackBerry Android Ipad Iphone iOS
 
Top 10
 
- How To Install Android Market & Google Apps On Kindle Fire
- How To Make Ubuntu Look Like Windows 7
- How To Add A New Account in MS Outlook 2013
- Get Android & Mac OS X Style Gadgets For Windows 7 & Windows 8 With XWidget
- How To Activate Microsoft Office 2013
- How To Install Actual Facebook App On Kindle Fire
- How To Create, View And Edit Microsoft Office Files On Kindle Fire
- Download Attractive Business PowerPoint Templates For Free At SlideHunter
- How To Use And Enable Hibernate & Sleep Mode In Windows 8
- How To Get Microsoft Office 2013 Trial Product Key From Microsoft