Start learning with our library of video tutorials taught by experts. Get started

After Effects Apprentice 09: Expressions
Illustration by John Hersey

Looping


From:

After Effects Apprentice 09: Expressions

with Chris Meyer and Trish Meyer

Video: Looping

Another really handy expression is the ability to loop an animation. I want to clean up my display by selecting Close All from the Comp panel and open up 04-LoopOut*starter. Hopefully, the Rotation keyframes have already been exposed for this layer, and I'm going to turn off the background for now and just remove the distraction. Now what we have is a simple two-keyframe animation-- I'll press 0 to RAM Preview--of this watch piece rotating in one direction. Let's say you want that to repeat, rocking back and forth.

Watch this entire course now—plus get access to every course in the library. Each course includes high-quality videos taught by expert instructors.

Become a member
please wait ...
After Effects Apprentice 09: Expressions
1h 37m Intermediate Jul 27, 2011 Updated Nov 29, 2012

Viewers: in countries Watching now:

Expressions are one of the most powerful but underused features in After Effects. They can be used to animate layer properties with code, as compared to explicitly keyframing every value in the Timeline, and have multiple parameters and layers that follow the lead of a master layer or controller effect, making it much easier to coordinate complex animations and quickly accommodate client changes. In this introduction, Chris Meyer shows how to let After Effects do most of the work by creating simple but very useful expressions that can be put to work on a wide variety of jobs.

The After Effects Apprentice videos on lynda.com were created by Trish and Chris Meyer and are designed to be used on their own and as a companion to their book After Effects Apprentice. We are honored to host these tutorials in the lynda.com Online Training Library®.

Topics include:
  • Creating and managing expressions
  • Linking together different parameters
  • Randomizing a layer's movement
  • Looping an animation
  • Controlling multiple layers from a single source
Subjects:
Video Motion Graphics Visual Effects
Software:
After Effects
Authors:
Chris Meyer Trish Meyer

Looping

Another really handy expression is the ability to loop an animation. I want to clean up my display by selecting Close All from the Comp panel and open up 04-LoopOut*starter. Hopefully, the Rotation keyframes have already been exposed for this layer, and I'm going to turn off the background for now and just remove the distraction. Now what we have is a simple two-keyframe animation-- I'll press 0 to RAM Preview--of this watch piece rotating in one direction. Let's say you want that to repeat, rocking back and forth.

You could do a lot of copying and pasting of keyframes and playing around with the Graph Editor, but there is a better way. I'm going to hold down the Option key on Mac, Alt key on Windows, click on the animation stopwatch for rotation to enable expressions and type in the following expression, loopOut. A quirk of the JavaScript language is that the first word is not capitalized, but every word after that is capitalized. And then I'm going to type open parentheses and inside quotes, I'm going to type pingpong.

Numbers can exist on their own in expressions, but when you use words as parameters in expressions, you need to surround them in quotes. Close parentheses, press Enter, and now let's RAM Preview this. And you'll see that my watch piece is now seamlessly repeating its animation over and over again, ping-ponging back and forth between its two keyframed values. The loop expressions are something that's much easier to understand if you make a trip into the Graph Editor, so let's go ahead and open that up. And you need to do two things to really work with expressions in a Graph Editor.

One is there's this little button here called Post-Expression Graph. This is how you get to see graphs in a Graph Editor or motion paths in the Comp panel after the expression has been applied. And as soon as I enable it, you'll see what is going on. The dotted line is a result of the expression continuing on this animation. The second thing I like to do is go down to the graph type options and choose Show Expression Editor. This will now show you any expressions attached to the selected property right here in the Graph Editor.

Once you're in this view, it's really easy to see what's going on. For example, if I go ahead and select this second keyframe for rotation and drag it earlier in time--I'll press the Shift key to make sure I keep it as original value-- you'll see that I merely oscillate more quickly. And I'll RAM Preview and there is the new animation. If I select both of the keyframes and pick them up and move them higher, I'm just going to change the value range used for the rotation. RAM Preview, now you'll see an offset in one direction.

I'm going to undo that. Also, if I move the keyframes later in time by holding Shift key again to keep the values the same, you'll see that loopOut only affects what happens after your keyframes. It does not affect what happens before the keyframes. Now if you do want something loop into an animation, rather than loop out of your animation, you just need to change this from loopOut to loopIn, and now you see that you have the opposite behavior. I'll press 0 to RAM Preview, and that's the result.

I'm going to undo back to my loopOut with the keyframes starting at the very start of the composition. You have loop types other than pingpong. For example, I'm going to double-click to select the word pingpong, make sure I leave the quotes, and type the word cycle. This says rather than go back and forth between the keyframes, repeat the keyframes. Press Enter in numeric keypad to accept the expression, and you can already see from the Expression graph exactly what's going on in this animation.

You almost don't need to RAM Preview it, but let's do that anyway. You see we keep snapping back to initial position. Another interesting variation is offset. This says rather than repeating the exact values you're at before, add or subtract those keyframes to where you left off. Now if that wasn't clear, let me just press Enter again, and now you'll see that the values keep descending. After it's gone to a negative extreme, it's going to use that as the new starting point to rock a little bit further.

I'll press 0 in numeric keypad. You'll see where it rocks and it continues on from word stop rather than rocking back, or starting over. So offset is another interesting loop option, and I'm going to go ahead and go back to pingpong, since that was a fun animation. There are a few other variations on the looping expressions. For example, if I was to place another keyframe, say, partway through this animation, I'm going to go ahead and click on my Add or remove keyframe switch so I've another keyframe right there.

Let's say, rather than loop that entire animation, I want to loop just these two keyframes. Well, you can do that. You need to go down into your expression, go after the word pingpong, type a comma to indicate that you're about to add another parameter onto the expression, and add a number. Now in typical programmer logic, if you want to repeat two keyframes, you need to enter 1. That says use one more keyframes than the last one for loopOut or the first one for loopIn.

Press Enter and you can see from the graph what's going on: we're now ping-ponging back and forth just between these two keyframes. If I was to change this to 2, that says reach two more keyframes from my out point. Now you see we have the full animation again. But just so you can see what's going on visually, I'll type 1, Enter, 0 to RAM Preview, you can see where it just gets stuck over in this part of the animation. There is another interesting option, particularly if you have a complex animation and just want to repeat the very end movement.

In addition to looping based on keyframes, you can also loop based on time. Instead of the expression loopOut, you need to type loopOutDuration. And again, the first letter is capitalized, except for the very first word of your expression--no spaces in between. You saw pingpong, cycle, and offset for your options of how to loop, but now rather than the number of keyframes, you set the length of time. Let's say that we want to loop the last 3/10ths of a second of this animation.

Press Enter and now you see that we're just going to go back to this point in time and then keep repeating that. RAM Preview. If I want to loop a half second, I'll enter 0.5. Now you see I'm repeating more of my animation. And just to give an idea of the sort of fun you can have with this animation, go ahead and open up 04-loopOut_final from the Comps_Finished folder, and you'll see we've created a number of little watch pieces with some variations on how they're looping.

I'll press 0 to RAM Preview. This will take a little while to queue up because there are so many layers going on here. And there is also some other fun expressions we have used, like using expressions to keep the drop shadow constantly falling off to the lower right of these objects. You'll see where we're doing things like offsets here, different speeds. You can go ahead and study this just as a reminder of what variations on loop expression can do for you. Now all that said, neither the linear interpolation nor the loop expression are our favorites. Our favorite expression of all time is wiggle, and that's what we'll cover in the next movie.

Find answers to the most frequently asked questions about After Effects Apprentice 09: Expressions.


Expand all | Collapse all
please wait ...
Q: This course was updated on 11/29/2012. What changed?
A: We have added exercise files designed for After Effects CS6. We also added a movie that shows our premium subscribers how to use the exercise files.
 
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.
Upgrade now


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

join now Upgrade now

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed After Effects Apprentice 09: Expressions.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Notes cannot be added for locked videos.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.