Easy Infinite Scroll Part 1

by carl schooff on February 22, 2011 · View Comments

in AS3 Tips,GreenSock Tweening Platform Tips

This movie requires Flash Player 9

Here is a fun little technique to get your brains spinning. This simple scroll technique can be used to scroll any number of items in a continuous loop. Use the “toggle mask” button in the swf above to see how the end clips are being lobbed off and sent back to the beginning. In this video I’ll start by showing you exactly how it works and how dynamic we will make it in part 2. I’m also revealing for the first time my slow motion loop explorer so you won’t miss a beat.

Watch the Video

Use the Slow Motion Loop Explorer

I spend a good deal of time using the Slow Motion Loop Explorer. Its important to understand that the steps that are being animated in reset() are transparent to the end user. I’ve only animated them to help you visualize how the code runs. The only animation the end user sees is the tween that takes place in scrollIt(). Below is the Slow Motion Loop Explorer that you can walk through at your own pace. It isn’t bullet proof so please refrain from clicking really quickly on the “step thru” button;)

This movie requires Flash Player 9

AS3 Code

import com.greensock.*;

var startX:Number=parent_mc.x;

function scrollIt() {
	TweenMax.to(parent_mc, .5, {x:"100", onComplete:reset});
}

function reset() {
	//move all clips over to the right
	for each (var mc in parent_mc) {
		mc.x+=100;
		if (mc.x==400) {
			//take the right-most one and set it back to the left
			trace("found end mc = " + mc.name);
			mc.x=0;
		}
	}
	//shift the parent so it looks like nothing moved
	parent_mc.x=startX;
	//scroll it again after 1 second
	TweenLite.delayedCall(1, scrollIt);
}

btn.addEventListener(MouseEvent.CLICK, toggleMask)

function toggleMask(e:Event = null):void{
	parent_mc.mask = (parent_mc.mask) ? null : mask_mc

}

toggleMask();
scrollIt();

Download CS4 Source Flas

Updated 3-30-11 to include the version you see on the site AND a backwards version

SNORKL_infiniteScroll-and-backwards.zip

Stay Tuned

Remember all that dynamic scroll goodness I discussed in the video is coming soon. Once you fully understand the mechanics of moving the elements around I’ll show you how to simply change the size of the mask and have it all work without messing with a bunch of funky numbers.
Here is Infinite Scroll Part 2

oh an while you’re here, perhaps you would enjoy a click on one of these shiny buttons below?

Post to Twitter Post to Facebook

  • Peps

    Excellent tutorial been looking for a way to do this in TweenMax/TweenLite for ages! Keep up the good work!

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

    Thanks Sam!
    I had a lot of fun with this.
    I’m really looking forward to part 2.
    Hopefully have that out early next week.

  • mj

    You inspired an idea. Had an old flash file of the “camera” moving through a forest. Toward the background or vanishing point.
    It was actually a loop. The trees (same ones) kept appearing as if through the fog. I was all done on the timeline in those days. Wow, this code might actually work for that. Hope you and Greensock stick around or else I’m in trouble. Keep them coming. Thanks mj

  • http://www.facebook.com/profile.php?id=1642004995 Patrick Mullady

    Great tutorial. The funny thing is what I took from this the most is that you are allowed to do 44*2 in the properties panel fields! I had no idea! Thats frickin killer!
    I’m gonna use the heck out of that. Sweet find for me! :)
    Keep on rockin!

  • http://www.snorkl.tv/2011/03/easy-infinite-scroll-part-2/ Easy Infinite Scroll Part 2

    [...] What? You missed Part 1??? That’s ok… Easy Infinite Scroll Part 1 [...]

  • http://www.facebook.com/profile.php?id=1642004995 Patrick Mullady

    What would it take to get the animation to go in the opposite direction?

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

    Hi Patrick,

    That had me thinking for a few minutes. I created a backwards version and updated the zip file in the link above. check it out.

    Carl

  • ::C::

     how can i add backwards and forwards navigation to this scroller? how should it be written? Or will there be a tutorial on this soon?

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

    I haven’t thought of combining backwards and forwards. If I think of a solution or create a tutorial I’ll post back here. If you need something in a hurry, activeden.net has a number of affordable banner rotators with navigation built in.

  • Curvwind8

    Do you have an AS2 version of this?

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

    nope. sorry. but really it shouldn’t be too hard to convert.

    get the as2 version of greensock
    replace .x with ._x

    update the button code not to use addEventListener

  • http://www.facebook.com/people/Angie-Foster/798855014 Angie Foster

    How do you import or connect the tweenLite and tweenMax actionscript?

blog comments powered by Disqus

Previous post:

Next post: