TimelineLite Ultimate Starter Guide: Controlling Playback
videos

TimelineLite Ultimate Starter Guide: Controlling Playback

Tutorial Details
  • Difficulty: Beginner
  • Platform: Flash (Flash Player 9+)
  • Language: AS3
  • Software used: Flash Professional CS5
  • Estimated Completion Time: 20 minutes
This entry is part 3 of 6 in the series TimelineLite Ultimate Starter Guide

In the previous session I went over how to create a basic TimelineLite. Today I will show you the methods and properties that you will use to control the playback of your TimelineLite. By combining these methods and properties you can extend the built in functionality of TimelineLite to create fast-forward and play/pause toggle controls. I’ll also show you how easy it is to set up a Slider component to use as a TimelineLite scrubber.


TimelineLite in Action

Let’s take a look at the final result we will be working towards:

You can find all the files used to create the SWF above in the source files for this tutorial.


Watch the Screencast

Don’t like ads? Download the screencast, or subscribe to Activetuts+ screencasts via iTunes!


TimelineLite Playback Methods

The following methods give you precise control over the playback of your TimelineLite

  • play() –Starts playing forward from the current position.
  • pause() – Stops the timeline.
  • reverse() – Makes the timeline go backwards. If you want to reverse the direction of the timeline only and not continue playback in the reversed direction you can pass in a forceResume parameter of false – i.e. reverse( false ).
  • resume() – Starts playing from the current position without altering direction (forward or reversed).
  • restart() – Plays the timeline from the beginning

Custom Playback Controls

By combining the built-in methods and properties its easy to create advanced functionality:

Fast-Forward – You can create a fast-forward control by increasing the timeScale property and forcing playback in a forward direction.

private function fastForwardHandler(e:MouseEvent):void
{
	tl.timeScale = 4;
	tl.play();
}

Play/Pause Toggle – To toggle between the playing and paused states just negate the paused property. It is important to make sure timeScale and reversed properties are set to the normal values as they could be altered by the fast-forward and reverse buttons respectively.

private function playPauseHandler(e:MouseEvent):void
{
	resetTimeScale();
	tl.reversed = false;
	tl.paused = !tl.paused;
}

Slider Component Scrubber – The Slider component makes it fairly easy to scrub through the timeline by altering the currentProgress of the timeline. The Slider is set to output values between 0 and 100. In the code this value gets converted to a number between 0 and 1.

import fl.controls.Slider;
import fl.events.SliderEvent;

slider.addEventListener(SliderEvent.THUMB_DRAG, sliderChange);

private function sliderChange(e:SliderEvent):void
{
	tl.currentProgress = slider.value * .01;

    //forces the timeline to stop when the scrubber is released.
	tl.pause();
}

Homework

What? You are giving me homework? Yes! I want you to be your best. Flex your mind muscle with this little challenge.

  • Create a TimelineLite that animates six items
  • Create play, pause and reverse buttons like in the demo file above
  • Create buttons with compound functionality like fast-rewind and slow-forward

In order to really learn this material nothing is better than diving in and getting your hands a little dirty.


Conclusion

So far I’ve given you a fair amount of information on creating and controlling TimelineLite animations. Although there are some obvious similarities in the way you control TimelineLite and Flash IDE timeline animations, I really love how TimelineLite gives animators so much more control with the reverse(), restart(), and resume() methods. The timeScale and currentProgress properties open up some really interesting possibilities that will be discussed even more in the future.

In the next video I will be showing you how to add labels to TimelineLite instances so that you can easily navigate to certain sections of your timelines. TimelineLite labels work very similarly to frame labels in the Flash IDE but with some added functionality. It’s going to be a lot of fun.

If you have any questions or comments on this tutorial – or your homework ;) – feel free to post a comment below.

Thanks for watching!


Other parts in this series:«TimelineLite Ultimate Starter Guide: Basic Methods and PropertiesTimelineLite Ultimate Starter Guide: Working With Labels»

Add Comment

Discussion 9 Comments

  1. Dimitree says:

    Hi, is it possible to control a nested MovieClip’s timeline with TimelinelIte? I mean If I place a MovieClip on stage – and want to stop it playing – kind of “freeze” its timeline?

    Thanks

    • Dimitree says:

      Ok, I got rid of the Timer Class and now everything works as it supossed to be. Rule of thumb- Don’t use Timer Class along with TimelineLite ( that was a big stupid mistake!)

      • carl schooff says:
        Author

        Hey Dimitree,

        Glad you took the time to watch and experiment! Thanks for posting your findings as well.

        In general, once you start controlling objects with TimelineLite/Max it is best not to use other methods to move those objects around or control them.

        Quite often people will build a TimelineLite/Max that moves a something around, and then they have a button that triggers an independent TweenLite/Max that hides it or does something else.

        When the TimelineLite/Max is restarted they often get unexpected results as this “external force” mangled some properties that conflict with recorded values in the TimelineLite/Max.

        Thanks again for watching.

        Carl

  2. Andre says:

    Very nice articles indeed. I always stopped using tweenlite since all my animations build with for-loop.

    But with this it helps me a bit more to get my animations work with this.

    But i have one question. Is it possible to manipulate the end values of an animation while its already playing?

    In my case i have a few background elements with interact with the main menu. They change their xy-position, scale and rotate. It would be cool if i dont need to stop the tweens by the kill method, but to make the transition between to become more fluid.

    And thanks for this great article. It must be alot of work to do.

    Kind regards
    Andre

  3. tuanduy says:

    can I use this tutorial to load swf and control it?
    thanks

  4. Excellent post and very useful thanks

  5. Miguel says:

    Carl this is great, it is simple yet effective (which means great coding), thank you. That being said the only thing I miss is a frame by frame button (both forward and reverse) so that you can control exactly where to get at when looking for specific frames on a long animation.

    Thank you again.

Add a Comment

To add a code snippet to your comment, please wrap your code like so: <pre name="code" class="html">YOUR CODE</pre>. You can replace the class name with "js," "css," "sql," or "php." If there are any "<" or ">" within your code, please search and replace them with: &lt; and &gt; respectively.