Converted Tween Animation Class in AS3

本文介绍了一个用ActionScript 3重写的过渡动画类,该类允许电影片段在不同位置间移动,并支持缩放、旋转及透明度变化等多种动画效果。此外,还提供了自定义事件分发器用于监听动画进度和完成状态。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Converted Tween Animation Class in AS3


是一个挺酷的过度效果,大家可以到原站点看看


http://www.reflektions.com/miniml/template_permalink.asp?id=441




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();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值