Elegant Cross-Fade and Zoom Effect for Banner Rotators and Image Galleries with Flash and TweenLite

by carl schooff on May 10, 2011 · View Comments

in GreenSock Tweening Platform Tips

This movie requires Flash Player 9

Here we have a very cool effect that, although fairly simple, is a bit difficult to do with basic timeline motion tweens. By relying on some core ActionScript fundamentals we can hammer it out in no time. The important thing to note is that the transition is non-linear, meaning we can navigate TO any image FROM any image. Click buttons in the swf above then come on in to see how we create this nifty effect.

Watch the Video

Six Core Fundamentals of ActionScript

In the video I harp on my belief that you can build just about anything using a mish-mash of the following code elements:

  1. Variables
  2. Buttons / EventListeners
  3. Conditional Statements
  4. Arrays / Loops
  5. GreenSock Tweening Platform: TweenLite/Max TimelineLite/Max
  6. Loading External Data and Assets with LoaderMax

This non-linear cross-fade and zoom technique uses the first 5! I can say with confidence that these fundamentals make up 90% of the things I’m paid to do with Flash.

AS3 Code Used in this File

import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.plugins.*;

TweenPlugin.activate([ScalePlugin]);

var clips_arr:Array = [audioJungle, themeForest, graphicRiver, activeDen, ocean, codeCanyon];

TweenMax.allTo(clips_arr, 0, {autoAlpha:0});
TweenMax.to(clips_arr[0], 0, {autoAlpha:1});

nav_mc.audioJungle_btn.ID = 0;
nav_mc.themeForest_btn.ID = 1;
nav_mc.graphicRiver_btn.ID = 2;
nav_mc.activeDen_btn.ID = 3;
nav_mc.ocean_btn.ID = 4;
nav_mc.codeCanyon_btn.ID = 5;

nav_mc.buttonMode = true;

nav_mc.addEventListener(MouseEvent.CLICK, crossFade);
nav_mc.addEventListener(MouseEvent.MOUSE_OVER, btnOver);
nav_mc.addEventListener(MouseEvent.MOUSE_OUT, btnOut);

//this variable stores a reference to the currently visible clip
var currentClip:MovieClip = clips_arr[0];

function crossFade(e:MouseEvent):void{

	//create a reference to the movieclip related to the button you just clicked
	var thisBtnsMovie:MovieClip = clips_arr[e.target.ID]
	trace(thisBtnsMovie.name);
	//make sure the currentClip isn't related to the button you just clicked
	if(currentClip != thisBtnsMovie){

		//hide the current clip
		TweenLite.to(currentClip, .5, {autoAlpha:0, scale:2, ease:Quad.easeIn});

		//show the clip related to the btn you just pressed
		TweenMax.fromTo(thisBtnsMovie, .8, {scale:0}, {autoAlpha:1, scale:1, delay:.2});
		}

	//reset currentClip to reflect the clip related to the button you just clicked
	currentClip = thisBtnsMovie;
	addChild(currentClip);
	addChild(nav_mc);
	}

function btnOver(e:MouseEvent):void{
	TweenMax.to(e.target, .5, {tint:0xffffff});
	}

function btnOut(e:MouseEvent):void{
	TweenMax.to(e.target, .5, {tint:null});
	}

With all that fancy code commenting and the thorough explanation in the video, don’t know what else I can add:) The source files should be pretty self-explanatory. As always, if you have any questions, just ask below!

Get the Goods: Flash CS4 Source Files

SNORKLtv_samples_zoomFade_CS4

Club GreenSock Membership Giveaways!

Yup, as mentioned in the video, I have a large handful of Really Green Club GreenSock Memberships to give away that have been generously donated by GreenSock.

Winners will also have the rare opportunity to become Shockingly Green for only $50 (marked down from $99!). I will be giving away the memberships for a variety of reasons, including but not limited to: re-tweeting articles, participating in the comments, and following on youtube, twitter or facebook.

I will be announcing the complete details shortly. To stay aware of your opportunities to win, simply get involved on:

Twitter: Follow
Facebook: Like
Youtube: Subscribe

The more you get involved, the higher your chances are of winning!

Official Contest Page Now Live!

Post to Twitter Post to Facebook

  • Merrick Brewer

    Another excellent tutorial. Have used plenty of these same techniques over the last few months, and then refining them further and further. Which then of course means you can write really good, functional code quicker and quicker.

    Really enjoying your series of tutorials and looking forward to the timelineMax ones that you mentioned. Have started using that now, and won’t ever go back to frame based animations (unless I really really have to).

    Also will be looking out for the competition, although I seriously doubt that any code I write will be ‘award’ winning!!

    Oh well, we can but try.

    Anyhoo, top stuff yet again Mr Snorkl…

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

    Merrick,

    I’m pleased to announce that you are the winner of the Un-announced Yet Very
    Official Pre-Contest Contest!

    The unpublished Pre-Contest Contest rules state that the first commenter on
    this post will get a Free Really Green Club GreenSock Membership.

    I’ve been waiting for a way to let the Snorklsphere know that I’m serious
    about rewarding participation. Although, there are going to be some more
    refined requirements for the contest in the future anyone can win at any
    time.

    You have been a model supporter on Facebook and here on Snorkl.tv and I’m
    honored to have you as a fan and award you this prize.

    I have your email address and will be contacting you with the details
    regarding claiming your prize. Being that the Official Contest is not yet
    underway, please give me a few days as I have to iron out a few details and
    communicate with GreenSock. When the real contest is in effect, prizes will
    be redeemable in a much quicker fashion.

    Thanks again for everything and enjoy your prize!

    Carl

    ps. just to clarify, coding-ability is not a factor in determining contest
    winners.

  • Merrick Brewer

    Holy S**t balls batman! I wasn’t expecting that! That’s really generous of you Carl, but to be honest, I think it’s me that owes you $50 for all the help you’ve given me at work. I introduced to greensock about a year ago when I first took up AS3 and haven’t looked back. Since then I’ve used loads of snippets of your code to string together the various projects I work on in my job, so any nugget of information is highly valued by me.

    Anyway, I won’t ramble on here as it’ll turn into some sort of gushing mess.

    Needless to say, bring on the next tutorial (something with LoaderMax would be great as I’m about to get stuck into it at work!)

    All the very best Carl, and thanks again. You’ve made my day!

  • http://twitter.com/Oct_Moon Khalid Robinson

    Thanks Carl. Can’t wait to mess with this tomorrow

  • Philippe Brosse

    Hello Carl. I’m a new-bee in AS3. Like Merrick, i’ve discovered Greensock about one year ago and Snorkl.TV a few months ago. What you show us is very useful, and so clear. A great pleasure for me every week now. To finish, only a word. Respect !

    Philippe Brosse
    Meaux – France

  • Merrick Brewer

    Totally agree. The clarity of these tutorials is what really makes them stand out against pretty much everything else on the interwebs. Short, bite sized chunks that you can easily adapt into whatever project you are doing. And before you know it, you are writing some excellent code, the flash file works perfectly and smoothly. We’re happy, and the clients are happy!

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

    Thanks Philippe. Its so kind of you to take the time to chime in. Very
    excited to serve you more in the future. I got a ton of stuff coming!

  • X10

    Hi Carl,
    Another really useful tutorial that you, once again, make look really easy!  I have to mirror Merrick’s comments that your tutorials are golden nuggets of edible code goodness.  Not only that, but they often keep me amused too! :)

    Keep it all coming.

  • rai

    can you use this in as2?

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

    There is an AS2 version of TweenLite, but there are quite a few changes that would have to be made for the button code.

    Unfortunately I don’t have the time to support both versions in my tutorials.

  • Artem

    Hi, Carl. I’m from Russia and my english is bad, I translate by Google, so forgive me for mistakes. You have no idea how I am thankful to you. Want to tell you thank you, your lessons helped me a lot.

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

    That is wonderful to hear Artem.
    Thank you!

    Google translated very well.

  • Marjp11114

    You’re a gentleman and a scholar! Thank you!

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

    thank you very much kind sir

  • WB

    Code works perfectly as a class in Gaia :)

  • Charlie

    Excellent tutorial, really helped me to understand :D

    Now, I’m really new to all this and so I hope this next question doesn’t come across as too stupid… But, is there a way to get the images on the banner to rotate independently, whilst still retaining the button functionality?

    I’ve been looking for a way to do this for what feels like forever.

blog comments powered by Disqus

Previous post:

Next post: