A few months ago I had released an easing tween class that I wrote in AS2 based on the easing formula posts. The basic principle is to get a clip to move, scale or rotate from point A to B with different movement equations. this is an alternative class similar to the fuse kit, the Robert Penner equations, the Zeh Fernando MC tween, the Zigo/Laco or the tween classes found in Flash. Here is the principle
import com.reflektions.tween.*;
var tween:Tween = new Tween();
var tobj:Object = {mc:mc,x:x,dx:dx}; //x init and dx final position
tween.initTween(tobj);
I rewrote the class in AS3 and you can download it here. I also added custom event dispatchers that dispatch events when the clip is animating and when tween completed. The movieclip reference and time (0 to 1) are also passed through the custom event.
// Add Listener to tween events
tween.addEventListener(TweenEventDispatcher.TWEEN_PROGRESS, progressListener);
tween.addEventListener(TweenEventDispatcher.TWEEN_COMPLETE, completeListener);
n.b: as far as passing properties go you can pass (x:,dx:) for x tweening, (y:,dy:) for y tweening, (r:,dr:) for rotation, (a:,da:) for transparency and (xscale:,dxscale:) and (y:,dyscale:) for scaling on both axis. Enjoy, here is an examples that tweens 5 different clips with different equations at different speeds.
import com.reflektions.tween.*; // <-- import for tween
import com.reflektions.tween.equations.*; // <-- import all tween equations
function initAnimation():void {
// define properties
var mc:MovieClip = follow_mc_1; // clip to tween
var x:Number = mc.x;
var dx:Number = (x == point_1.x) ? point_0.x : point_1.x; //switch target accordfing to position
var tween:Tween = new Tween();
var tobj:Object = {mc:mc,x:x,dx:dx};
tween.initTween(tobj,Shubring.easeInOut,10); // or pass extra parameters sucha as equation and speed
// Add Listener to tween events
tween.addEventListener(TweenEventDispatcher.TWEEN_PROGRESS, tweenProgressListener);
tween.addEventListener(TweenEventDispatcher.TWEEN_COMPLETE, tweenCompleteListener);
}
// Check Complete
function tweenCompleteListener(e:TweenEventDispatcher):void {
// Accordig to completed reset animation
if (e.params.target.name == "follow_mc_1") { // check to see if target is clip we animated (optional)
initAnimation();
}
}
// Check progress
function tweenProgressListener(e:TweenEventDispatcher):void {
trace(["progress... ",e.params.target,e.params.time])
}
// Initiate
initAnimation();
本文介绍了一个用ActionScript 3重写的过渡动画类,该类允许电影片段在不同位置间移动,并支持缩放、旋转及透明度变化等多种动画效果。此外,还提供了自定义事件分发器用于监听动画进度和完成状态。
1万+

被折叠的 条评论
为什么被折叠?



