Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Looping

From: After Effects Apprentice 09: Expressions

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.

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.

Show transcript

This video is part of

Image for After Effects Apprentice 09: Expressions
After Effects Apprentice 09: Expressions

20 video lessons · 10803 viewers

Chris Meyer and Trish Meyer
Author

 

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
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.


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 "Already a member? Log in

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

Your file was successfully uploaded.

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.