Friday, April 25, 2008

ActionScript Transitions - Scripting Animation Effects

Tonight I had a chance to make use of the Flash ActionScript based Tweening effects - specifically, I used the TransitionManager object.

I have to say, I'm really impressed. Not only is it possible to get impressive looking animation effects via ActionScript, but it's actually not hard to use.

Here's a tiny example that I through together to better understand the API. Who the heck nows if this is good style, but hey, if you find it useful, that's great. You can get the FLA here.

And here's the ActionScript that drives this:

/*
 * A chance to play with ActionScript Transitions. By Ben Simon.
 * http://benjisimon.blogspot.com/
 */
stop();
import mx.transitions.*;
import mx.transitions.easing.*;

function warp(clip) {
	var mgr= new TransitionManager(clip);
	mgr.startTransition({type:Fade, direction:Transition.OUT, 
						duration: .5, easing:None.easeNone});
	mgr.addEventListener(
		"allTransitionsOutDone",
		{ allTransitionsOutDone: function() { 
			clip._x = Math.round(Math.random() * (Stage.width - clip._width));
			clip._y = Math.round(Math.random() * (Stage.height- clip._height));	
			var mgr= new TransitionManager(clip);
			mgr.startTransition({type:Zoom, direction:Transition.IN, 
								duration: 1, easing:Bounce.easeInOut});
		}});
}

var loader = new MovieClipLoader();
loader.onLoadInit = function(target_mc) { 
	target_mc.onRelease = function() { 
		warp(this);
	}
	warp(target_mc); 
};
loader.loadClip("http://static.flickr.com/6/86690184_ac1e205488_o.gif", target_mc);

No comments:

Post a Comment