---
title: "Converted Tween Animation Class in AS3"
author: "txf2004"
date: "2007-12-29T20:39:00Z"
tags: []
slug: "converted-tween-animation-class-in-as3"
draft: false
lastmod: "2007-12-29T20:39:00Z"
id: 606622
url: "https://txf2004.iteye.com/blog/606622"
---

Converted Tween Animation Class in AS3

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

[http://www.reflektions.com/miniml/template\_permalink.asp?id=441](http://www.reflektions.com/miniml/template_permalink.asp?id=441)&lt;!-- Begin .post --&gt;

A few months ago I had released an [easing tween class](http://www.reflektions.com/miniml/template_permalink.asp?id=415) that I wrote in AS2 based on the [easing formula posts](http://www.reflektions.com/miniml/search.asp?search=tween). 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](http://www.mosessupposes.com/Fuse/), the [Robert Penner](http://www.robertpenner.com/) equations, the Zeh Fernando [MC tween](http://hosted.zeh.com.br/mctween/), the [Zigo/Laco](http://laco.wz.cz/tween/) or the [tween classes](http://livedocs.adobe.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001502.html) 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](http://www.reflektions.com/miniml/uploads/com.reflektions.tween.zip). 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 com.reflektions.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();