ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

# Easily turning opacity on or off over frames

FAQ   •   VIEW ALL
 Easily turning opacity on or off over frames on Oct 17, 2011 at 8:46:43 pm

I've uploaded a basic diagram to help demonstrate what I'm trying to achieve here.

If I have a piece of footage or a comp that I want to appear for 1 frame, then disappear for a frame showing the frame below, then on, off, on, off... and so on.

I could either make the transparency 0%, 100%, 0%, 100% and so on, copying the keyframes manually but there must be an easier way.

I just wondered if maybe there's an easy way using code possibly to say 'turn on this layer for 1 frame, then turn it off for 1 frame, etc. etc.'?

I really do love good design - http://www.splurj.com

 Re: Easily turning opacity on or off over frameson Oct 17, 2011 at 9:02:31 pm

[Scott Green] "I just wondered if maybe there's an easy way using code possibly to say 'turn on this layer for 1 frame, then turn it off for 1 frame, etc. etc.'?"

Yes -- welcome to expressions. I'll answer your question here, but you can also get a lot of help in the After Effects Expressions forum [link].

Alt-click the opacity stopwatch for your upper layer, then paste in the following code:
```frames = 2; if (timeToFrames() % (frames*2) < frames) 100 else 0;```

This will give you a pattern where the upper layer is on and then off for the number assigned to the "frames" variable. As shown, you'll get two frames on, then two frames off.

The math goes as follows:
• Get the current time in frames (for example, frame 5)
• Divide that value by "frames" times 2, and return the remainder (in this case, divide 5 by 4, and get a remainder of 1)
• Compare that value against the "frames" value; if it's lower, return 100% to the Opacity value. If it's higher, return 0% (and 1 is less than 2, so frame 5 will have an opacity on the upper layer of 100%).

Walter Soyka
Principal & Designer at Keen Live
Motion Graphics, Widescreen Events, Presentation Design, and Consulting
RenderBreak Blog - What I'm thinking when my workstation's thinking
Creative Cow Forum Host: Live & Stage Events

 Re: Easily turning opacity on or off over frameson Oct 19, 2011 at 1:42:02 pm

That works really really, just what I was looking for, thanks very much :)

I really do love good design - http://www.splurj.com

 Re: Easily turning opacity on or off over frameson Oct 18, 2011 at 3:44:52 pm

I'm rather fond of setting the first few keyframes then using the expression:
`loopOut("cycle");`

-cg

p.s. and when i say 'few', i mean the first 3 keyframes