Bullet-Proof TimelineMax Transitions Part 3: Reverse Out or Forward Out

by carl schooff on April 5, 2011 · View Comments

in GreenSock Tweening Platform Tips

This movie requires Flash Player 9

Here we go, the last technique in my Bullet-Proof TimelineMax Transitions series. This technique allows you to have a unique animate out sequence for each section as well as do the reverse from the previous technique. Notice in the swf above that if you click to go to a new section there are 2 possible transitions: If the current section is fully resolved then a custom out animation will play. If the current section is still building then it will reverse out quickly. Take a look inside to see how its done.

Watch the Video

Background

Make sure you have watched the previous tutorials in this series:
Bullet-Proof Transitions: Teaser / Introduction
#1 Jump to Section
#2 Reverse Out
#3 Reverse Out with Custom Out : You are Here:)

Visualization of Label Analysis

Unlike the other two techniques where there was only one course of action when a transition took place, here we have 2 options. The way we decide whether to play forward or reverse is based on where the playhead is when a new section is requested. We do this by analyzing the next frame label in our timeline. As in the videos I use a Flash IDE timeline as a reference:

Reverse current section build if it is still animating in

Play unique forward-out animation if the current section’s in animation is complete

How to Analyze the Next Label with AS3 Code

In order to figure out if the next label is a section_in, we will use TimelineMax’s getLabelAfter() method. This method has 2 uses:

1) Get the next label after the playhead : someTimeline.getLabelAfter()
2) Get the next label after some point in time: someTimeline.getLabelAfter(someTime or someLabel)

In either case getLabelAfter() returns a string value representing the next label. In my file that label will either contain “_in” or “_complete”. such as:

home_in
home_complete
blog_in
blog_complete
portfolio_in

We are going to test to see if the next label is someSection_in.

AS3 Code to Detect Which Way to Go

if (tl.getLabelAfter().indexOf("_in") != -1) {

      //label contains "_in" so playhead is at "someSection_complete"
       trace("go forward");

       tl.tweenTo(tl.getLabelAfter(), {onComplete:introduceTargetSection});
      }

else {
     //label does not contain _in (playhead is between _in and _complete);
     trace("go back");

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

Download Flash CS4 Source Files

SNORKLtv-forwardOut

THANKS!

Thanks everyone for all the feedback on this series in the comments and on facebook and twitter. So glad to hear you are enjoying it.
I’ve had a lot of fun working on these videos. Don’t hesitate to ask questions if you need more clarity on anything.

Carl

Post to Twitter Post to Facebook

  • guest

    Can you maybe give a hint how to make something like that in a oop way, a systems like GAIA uses but more simple

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

    too make it more oopy, each section could be its own object with it’s own animateIn() and animateOut() methods. these methods would return the appropriate section timelines that could be added to a master timeline like the one I created. For a fuller explanation read TIP 3 here:
    http://www.greensock.com/tweening-tips/

    its a slightly different approach but if you combined the 2, you would have unlimited potential.

    c

  • Snefer

    Carl, you made the awesome. :D

  • imezei

    great tutorial, thanks.
    can you make part 4 of this tutorial series, explaining more about this oop approach, please?

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

    i think i replied to you on FB, either way, i’m working on something like this now. will shoot for next week. its a bit more complex in scope than my avg tutorial.

    carl

  • guest

    thx for the more complex tutorial ;)

  • imezei

    thanks, i am looking forward to it.

  • Zacharykutz

    Hey Carl!

    Used this code to do the nav for my Zombie themed restaurant website for a class project. My teacher was thoroughly impressed and we’ve all been checking out your work as of late!

    Im running into a little trouble with this code though. The movie clips I am transitioning in are stacked on top of each other. The Mc loaded is the only one visible but the mc’s with alpha 0 are still above and below that later. And within the MC’s I want to have rollovers, and different functions, etc. The site is almost fully coded but the only MC that “works” is the MC on the top layer. Do you have a solution for this. Has anyone else run into this either?

    Thanks so much for this tutorial though. This got me excited about programming my site again after a couple nav’s I was using just wasn’t “doin’ it” for me!

    -Zachary

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

    glad you and your class are enjoying the tutorials!

    What you need to do is edit your fade out transitions so that they use
    autoAlpha instead of just alpha. autoAlpha will automatically set the
    visible property to false thus preventing buttons on different layers in
    different movie clips from interfering with each other.

    tl.append(TweenMax.to(home_mc, .5, {alpha:0}));

    SHOULD BE: tl.append(TweenMax.to(home_mc, .5, {autoAlpha:0}));

    also in the beginning of the code make sure in the loop that sets alpha = 0
    to all clips that you use a TweenMax with autoAlpha = 0 as well.

    var section_clips = [home_mc, blog_mc, portfolio_mc, about_mc];
    for (var j:Number = 0; j < section_clips.length; j++){
    TweenMax.to(section_clips[j], 0, {autoAlpha:0});
    }

    let me know if that works for you.

    Carl

  • Zacharykutz

    Hey Carl!

    Everything is working now. The autoAlpha stuff did the job. On first click the animations/tweens aren’t playing in how they’re supposed to but after returning to them (after clicking on another link) they play in and out the way I want them to. My file size is approaching 30mbs. I’m thinking that might have something to do with it…idk.

    Thank you for your help. I keep sending more and more people over here when I can!

    -Zachary

  • Anonymous

     Hello, I have used this tutorial in my website. It is very cool!!! :) But I need help. I’m actually a beginner in AS3. I like how portfolio comes in and out. But I don’t know how to integrate XML driven gallery in this animation. I’m not a programmer so it’s actually difficult for me to understand. Can you help me?  If you don’t understand something, I can try to explain. English isn’t my first language. :) Please help help help :)  

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

    Hello AniMiLedi,

    I’ve gotten this question a few times. Unfortunately there is not a quick
    answer. I will be doing a tutorial on this. I’ve put it on the top of my
    list. Hopefully it won’t be too long. I am going to be using LoaderMax which
    is perfect for this.

    http://www.greensock.com/loadermax/

    stay tuned

    Carl

  • Anonymous

    thank you for your answer :) )))!!! can you say me how long it takes for you
    to do this? Becouse I’m doing this for my graduation work in college :)
    thank you so much!!! :)

    2011/5/17 Disqus

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

    “can you say me how long it takes for you to do this?”

    No, I don’t know. It would take me a few hours to build it. Posting a
    tutorial about it is another matter. I suggest you google “Flash xml gallery
    tutorial” as there are many out there. Perhaps your professor has some
    suggestions.

  • Anonymous

    I know how to do xml gallery :( But I don’t know how to integrate it in this
    nice animation thats the main problem..:( I searched for tutorials how to
    use LoaderMax, but I can’t find nothing really helpfull (or I’m too dumb for
    this) :( It will be nice if you can make it without a tutorial (and maybe
    send me into my email), I think I can find out how it’s done by myself…
    Actually I’m doing this all the time when there is a possibility to download
    project files :) What about my professor… well she doesn’t know
    programming… :D I know I know how this sounds… :) )))

    2011/5/17 Disqus

  • Anonymous

     Ok, I’m trying to figure out all this LoaderMax thing myself… actually I’m stuck, I’m not shure what to write in that place where you need to write .container

    var iLoad:ImageLoader = new ImageLoader(“images/thumbs/” + xImgList[i].@url, new ImageLoaderVars()
    .name(xImgList[i].@name)
    .width(nImgWidth)
    .height(nImgHeight)
    .smoothing(true)
    .container(????) maybe you have an answer?

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

    the container is a A DisplayObjectContainer into which the
    ContentDisplay Sprite
    should be added immediately.

    the container is a just an object you can specify that your image should be
    loaded into. when you specifiy the container, the image automatically shows
    up. if you do not configure a container, you need to manually use addChild()
    onComplete to have your image appear.

    if you are using my file as a model, each one of the “pink boxes” in the
    portfolio_mc would be the container for each image.

  • Anonymous

    Okey Carl, I’m done with addin buttonMode true. But now I’m really in trouble with making gallery looking like this http://www.files.riacodes.com/flash_zoom-photos-panel/ . Can you help me. please :) )) 

  • Ann Ezzell

    I’ve been playing around with various tutorials from this site, trying to learn by dissection ;-)

    Can you please explain the need for these lines? It doesn’t appear to make a difference if I comment them out. 
    var section_clips = [home_mc,blog_mc,portfolio_mc,about_mc];for (var j:Number = 0; j < section_clips.length; j++) { section_clips[j].alpha = 0;}

    I understand what they're doing, but they don't appear to be necessary.

    Thanks!

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

    those lines set all the section clips to have an alpha of 0 so that they
    can’t be seen.

    the reason they don’t seem necessary because commenting them out has no
    visible effect is because all the child elements in those sections start
    with an alpha of 0 and fade in.

    It just so happens when i built this I had all the child elements of a
    section fade in from alpha 0 also, so there really isn’t anything to see on
    stage until those animations play.

    each section has something like this:

    tl.appendMultiple(TweenMax.allFrom([blog_mc.blog1_mc,
    blog_mc.blog2_mc
    ],
    .5, {y:”50″, alpha:0}, .2));

    NOTE THE alpha:0

    if you remove it. all those elements will now be visible on the stage when
    your timeline starts… which would be bad if the parent blog_mc didn’t have
    alpha:0 as well.

  • http://twitter.com/Gorillawit Rawley Speed

    Hey Carl :D , I’ve used this tutorial as the basis for a couple of my flash sites since I first saw it a couple months ago (awesome work by the way (pun intended)), but now I am trying to use it for a project that requires that the movie continually play AND have navigation. Basicly what I need to achieve can be seen here http://www.apple.com/imac/  (Apple’s site of course…). Seemed as simple as changing the timelineMax to loop forever with repeat=-1 and change the final tl.tweenTo(“someLabel”) to just tl.play() but I’m getting nowhere. Any suggestions?

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

    Hi Rawley,

    Thanks for writing. Very glad to hear this stuff gets used in the real
    world.

    I can’t figure this out now, but hopefully tonight. Its an interesting
    situation.

    I’m thinking that I’ll have some sort of array that keeps track of all the
    sections.

    I’ll have an autoPlay function that figures out what the next section is and
    tweens to its “_complete” label. when that tween is done it will call a
    function that waits 4 seconds or so before calling autoPlay again.

    something like

    function autoPlay(){

    //some code to figure out what the next section is

    tl.tweenTo(nextSection +”_complete”, onComplete:setTimer);

    }

    also I’ll have to throw something in that kills the autoPlay once someone
    clicks a nav button.

    its totally possible but will probably take a few minutes to hammer it out
    and I don’t have much time until this evening.

    carl

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

    hi rawley, 

    i think its pretty solid, but can’t guarantee bullet proof:

    http://ge.tt/9XFbww5?c

    i commented where the new stuff goes. 

    it will autoplay and loop until the user clicks a nav button.

    the first time you run just watch it loop all the way through.

    you can set how long the delay on each section is in the 

    waitForNext() function.

    I didn’t comment everything.

    give it a look, let me know if works for you

    Carl

  • http://twitter.com/Gorillawit Rawley Speed

    Hey Carl, I tried out your updated code but was getting some bugs. From what I can gather, if the navClicked function is called before the currentSection has reached the end of it’s “_in” tween, the new code is skipped initially and the playhead runs as it did in the original code except that once it gets to it’s next label it immediatley continues to the following “_in” label and calls the waitForNext function then . I tried tinkering with a few things like trying to add the {onComplete:waitForNext} call to the last tl of each sections “_in” tweens or using a boolean to track whether a nav button has been selected or if the playhead arrived at it’s label through the autoPlay function but no luck. I’ll keep hammering at it :)

    Yeah I’ve definetley used a bunch of stuff from your vids in my work and projects (sometimes stringing two or three of your tips together). Usually I’m the guy other people come to to help fix their code so I really appreciate any help you can give.  Thanks and keep the vids coming!

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

    Thanks for the report. I’ll give it a look.

    C

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

    after further investigation, it seems that if it is in autoPlay mode and you do a navClick after a section has fully animated in and is just sitting still… then the navClick won’t kill the delayed call and the autoPlay will kick in after the section you clicked on is reached.

    go into the navClick function and put this on the first line

    TweenMax.killDelayedCallsTo(autoAdvance);

    that seems to work. let me know if you find any other troubles or if this works for you.

    Carl

  • http://twitter.com/Gorillawit Rawley Speed

    Sorry still not able to get it working correctly. The results im getting are when a nav is clicked before the _in label’s tween has completed, the movie reverses, goes to the targetSection’s _in label, tweens, then stops indefinitley, If a nav is clicked after the _in label’s tween has completed (and has paused), the movie goes to the current section’s _complete section, tweens out, goes to the targetSection’s _in label, then once the _in tween has completed it immediatly continues to the _complete label’s tween, goes to the following label’s _in tween then pauses indefinetley as well.  If i understand correctly, killDelayedCallsTo will completley kill all future calls to the function autoAdvance. Once a section has been clicked I need the current section to run it’s _complete label’s tween, then proceed to the targetSection’s _in label, finish that label’s tween, pause (using the waitForNext function maybe?), then continue.

    Thanks for you’re help on this, let me know if I’m not clear enough in my explaination or if you are getting different results

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

    Hi Rawley, 

    I can’t seem to simulate any bugs when clicking during an _in animation, once the animation is resolved (paused) or on its way to _complete.

    I slowed down the timeScale to test.

    here is my latest file.

    let me know if it works for you.

    http://ge.tt/8XThu26?c

  • http://twitter.com/Gorillawit Rawley Speed

    After some more tinkering I finally got it rolling! When I first opened the file, the movie was still not doing what I needed. Of course the simplest explanation is always the right one so after adding the  TweenMax.killDelayedCallsTo(autoAdvance), I also added an {onComplete:waitForNext} to the introduceTargetSection timeline. Works like a dream :D

    Thanks so much for all your help, you can check it out here
    http://ge.tt/9KQUz26?c

  • Renato

    Hi Carl, 

    it’s amazing !!!!

    I made some alterations in your file by creating new buttons on root, but i’m having problems with loop and i can’t fix it.

    Could you help me please ????

    file:

    https://rapidshare.com/files/2765375878/inOut_reverseOut-or-forwardOut_finished3.fla

    Thanks Man  and sorry for bad english !!!!!!!

blog comments powered by Disqus

Previous post:

Next post: