Bullet-Proof TimelineMax Transitions Part 2: Reverse Out

by carl schooff on April 2, 2011 · View Comments

in GreenSock Tweening Platform Tips

This movie requires Flash Player 9

This Bullet-Proof TimelineMax Transition which I call the Reverse Out, tells the current section’s build sequence to play quickly in reverse before introducing the next section. Click a few buttons in the swf above to get the idea. To learn more jump on in.

Watch the video

If this is your first time jumping into this series I strongly suggest you watch the previous videos:

Other Bullet-Proof TimelineMax Transitions

Bullet-Proof Transitions: Teaser / Introduction
#1 Jump to Section
#2 Reverse Out : You are here:)
#3 Reverse Out with Custom Forward Out

How does this work?

This video is a direct continuation of Jump to Section. In that example we were able to directly set our currentSection variable appropriately because currentSection became targetSection as soon as any button was clicked. We didn’t care much about where we were… only where we were going.

In order to Reverse Out, it is imperative that our app always knows what section we are in. In order to really bullet-proof our app we want it to stand up even if the animation is playing all the way through without any user interaction. To do this, we trigger a function called setSection every time a new section starts to build.

Adding onSart and onStartParams

By using the onStart callback, we can trigger a function when any tween in our timeline begins. We can also pass in an array of parameters for that function with the onStartParams special property. To notify our app that our timeline has started the about section we would do the following:

tl.addLabel("about_in", tl.duration);

//this is the pertinent line. note onStart and onStartParams special properties.
tl.append(TweenMax.to(about_mc, 0, {alpha:1, immediateRender:false, onStart:setSection, onStartParams:["about"]}));

tl.append(TweenMax.from(about_mc.about_mc, .5, {x:"100", alpha:0}));
tl.append(TweenMax.from(about_mc.aboutCopy_mc, .5, {x:"-50", alpha:0}), -.25);

//this function will be called when each build starts
function setSection(section) {
	currentSection=section;
	trace("setSection to " + currentSection);
}	

You will need to define onStart and onStartParams for each section of your timeline.

Update the navClick function

The navClick() function will behave a bit differently then in Jump To Section as it needs to:
-rewind the current section
-call a function called introduceTargetSection after the rewind takes place

function navClick(e:MouseEvent):void{
	trace(e.target.ID);
	targetSection = e.target.ID;

	if(targetSection != currentSection){

	//speed up the timeline (long transitions get boring);
	tl.timeScale = 2;

        //we know what section we are in so let's rewind to it's _in label
        //when that tween is complete we will go to the requested/target section

	tl.tweenTo(currentSection + "_in", {onComplete:introduceTargetSection});
	}
}

Introduce targetSection

function introduceTargetSection(){

        //bring timeScale back to normal
	tl.timeScale = 1;

        //tween from target section's "_in" label to "_complete"
	tl.tweenFromTo(targetSection + "_in", targetSection + "_complete");

}

Benefit of Reverse Out

You get a really cool section-out animation without doing any extra work;) I strongly believe it is important that this out sequence goes fast. You don’t want people waiting too long to get to where they want to go. Experiment with different timeScale values.

Coming Soon

#3 Reverse Out with Custom Out Technique
This transition will reverse out if you request a new section while a section is building. If the section is fully complete a custom out animation will play.

To get a quick look at all the techniques go to Bullet-Proof TimelineMax Transitions Overview

Download Flash CS4 Source

Investigate these files and feel free to alter the animations.
SNORKLtv_reverseOut Flash CS4

More Resources

Check out my other TimelineMax Tutorials on Snorkl.tv.

Learn more about TimelineMax/Lite from GreenSock.

Read the Official TimelineMax Documentation to see all the cool stuff it is capable of.

Post to Twitter Post to Facebook

  • X10

    Carl, I’m always in awe of how tight and clean your code is. When I learn more about AS3 and Tween* I hope I will be able to make the awesome too.

  • Snefer

    i screw up apparently. When I press another button everything is reversing to “home” an then show directly requested subsite. I am clueless.

    also i had to
    var currentSection:String = “bio”;

    otherwise flash was joyfully insult me with

    Error: TimelineLite error: the null_in label was not found.
    at com.greensock::TimelineLite/parseTimeOrLabel()[D:Projeckt4gry2comgreensockTimelineLite.as:469]
    at com.greensock::TimelineMax/tweenTo()[D:Projekty4gry2comgreensockTimelineMax.as:365]
    at _4gitary2v7_fla::MainTimeline/GnavClick()[_4gitary2v7_fla.MainTimeline::frame1:230]

    here is pastebin if you feel up to it
    http://pastebin.com/YL6FC49J

    i am sure that this is some stupid omission. ><

    code looks v. massive but its solid, Mainly its abuse of your knowledge ;D

  • http://www.snorkl.tv/ carl schooff

    Hi Snefer,

    Your code looks great. very neat. Everything that I thought might be a
    problem looks like you did it exactly right.

    the error *null_in* leads me to believe that currentSection is not being set
    (even though your code looks good).

    put a trace in:

    1. function setSection(section) {
    2. currentSection=section;
    trace(“currentSection = ” + currentSection)
    3. }

    would like to verify that setSection is working as planned.

    make sure you are using the latest version of the greensock classes or the
    ones from my source files.

    ———

    I’m really interested to see how this works as it looks like you put a lot
    of effort into this.

    If you want to post an fla for me to look at it, I’ll go over it later
    tonight.

    check out http://ge.tt/ for file sharing.

    Carl

  • Snefer

    I used your greensock package, it seems my was out of date. Everything works excelent now. I am definetly going to share link to final project.

    thx Carl, I would never suspect that library is out of date ;D

  • http://www.snorkl.tv/ carl schooff

    Glad to hear you got it working. your code looked great. I look forward to
    seeing what you made.

    Carl

  • jack

    I appreciate your tutorials, thank you so much for your efforts.

    Just curious on how you would change the code to target a tweened movieclip to play along a timeline rather than the scripted animation. Is there a way to reference keyframes using the duration method.

    I would also love to see how you work the gallery (portfolio) in this example.

    Thanks again and I look forward to seeing more tips! Great work!!

  • http://www.snorkl.tv/ carl schooff

    Hi Jack,

    Yes you can control the main Flash Timeline or any MovieClip timeline with
    the frame and frameLabel plugins:
    http://www.snorkl.tv/2010/10/overview-of-tweenmax-framelabel-and-frame-plugins-nifty-way-to-play-a-flash-timeline-backwards/

    once you create a simple frame tween:
    TweenMax.to(jumper_mc, 1.1, {frame:55});

    you can append it to a timeline like so

    tl.append(TweenMax.to(jumper_mc, 1.1, {frame:55}));

    —–

    as for building out the portfolio section, I didn’t have any intentions of
    going any further with the series and used the portfolio section just an
    example of moving a lot of stuff around. Now that I’m doing more with
    LoaderMax I will be doing some tutorials on loading swfs and images and will
    try to incorporate a similar style.

    Thanks for watching

    Carl

  • jack

    Thanks so much for your reply. I can’t believe I missed this prior example, this is very helpful.

  • Er Ds

    Thanks for the Carl, I have a question, can we assign an ID to a button?

    Object(this).btnBar_mc.cbtn1_btn = “k1″;

    where cbtn1_btn is a button

  • Mighty Flash Gordon

    Hi carl,

    Ive just came across this and it is exactly what ive been searching, You are awesome.
    I was wonder though, how would you do this for multiple loaded swf’s instead of a single swf using labels and timeline?

    So for example:

    The first swf (lets say its called mainIndex.swf) loads all swf’s in an array using LoaderMax.

    Then have it act the same way as “bullet-proof-timelinemax-transitions-part-2-reverse-out”

    The reason I ask is, if the single swf is more then lets say 10 meg for example then it would take a while to load and the user may have to wait - Where as if you had multiple swf’s loaded by LoaderMax the user has something to look at while the other swf’s load in the back ground.

  • http://www.snorkl.tv/ carl schooff

    i don’t know that there is an easy solution. its kind of difficult to build a timeline when all of the assets that are needed aren’t loaded yet. I would suggest taking an approach similar to this tutorial: http://www.snorkl.tv/2011/05/real-world-benefits-of-oop-with-as3-for-the-completely-terrified-greensock-homepage-animation-case-study/where each slide has its own animation that gets glued into a master timeline. that tutorial focuses on using separate classes that contain various animations. technically when each of your swfs load, the parent swf could fetch animateIn and animateOut sequences from the child swfs and append them into one timeline. hopefully that is of some help. My gut feeling is that isn’t going to be totally easy.

blog comments powered by Disqus

Previous post:

Next post: