Swapping source images with an expression

Moderators: Disciple, zlovatt

Post Reply
ahettinger
Posts: 13
Joined: March 5th, 2008, 11:48 am

This seems like something AE was not really meant to do, so I'm not sure if there's a simple answer... anyway, lets say I have a list of 50 images in a comp, and I want to display one of those images based on the value of a variable. I have thought of two approaches:

1. Somehow swapping the source of the image, either the file source or the project source...I doubt this is possible with an expression, but just wanted to throw it out there.

2. Including all the images in a comp and dynamically adjusting the opacity. This seems like a more viable approach, but the only solution I can think of involves putting an expression on every layer. While it wouldn't be too hard just to copy the expression to every layer, I'm wondering if there is a way to do this with an expression on just one layer.

Thanks as always AEnhancer folks!
Dan Ebberts
Posts: 320
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

You'll need an expression for each layer. In general, put your variable in a slider control (so all the expressions can get at it). Your opacity expression should then look something like this:

myVar = Math.round(thisComp.layer("Control").effect("Slider Control")("Slider"));
if (myVar == index) 100 else 0


Dan
kobyg
Posts: 128
Joined: December 7th, 2007, 10:11 am

You can also get what you want in a different approach.
Precomp all your images into one composition, make each image 1 frame long in the timeline, and sequence the layers (using Animation -> Keyframe Assistant -> Sequence Layers), with no overlap. This way you will get a comp where each frame shows a different image. Now just return to the main comp and use the Time Remapping to show the desired frame.
(you can use a simple expression: if you want to show image number k, use for the time remapping: k*thisComp.frameDuration)

Koby.

p.s.: This approach doesn't require applying expressions to each image layer, but will work only if you want to cycle for still images (not videos).
Post Reply