一个AS3的运动效果类库

这是boostworthy开发的一个AS3 Animation System v2.0
用于做一些缓动效果,其中利用了rebert penner的缓动公式,可以控制位置,颜色,透明度,等等属性,或者是自定义的对象属性,其中还有PathTween等实用效果,有一个TimeLine类,模拟了flash中的时间轴功能,非常强大。
下载地址:http://www.boostworthy.com/blog/?p=170

下面是俺用这个类库做的一个效果,如果觉得卡,点击flash区域可以停止或继续运行

[kml_flashembed movie="http://harryxu.cn/demo/AnimationTest.swf" height="400" width="480" /]

package
{
import flash.display.Sprite;
import flash.display.Shape;
import flash.display.Graphics;
import flash.display.DisplayObject;
import flash.events.Event;
import flash.display.StageScaleMode;
import flash.display.StageAlign;
import flash.events.MouseEvent;
 
import com.boostworthy.animation.sequence.Timeline;
import com.boostworthy.animation.management.AnimationManager;
import com.boostworthy.animation.sequence.tweens.PathTween;
import com.boostworthy.animation.easing.Transitions;
import com.boostworthy.animation.rendering.RenderMethod;
import com.boostworthy.events.AnimationEvent;
import com.boostworthy.geom.Path;
import com.boostworthy.core.Global;
 
 
 
 
[SWF(backgroundColor="#000000", frameRate="31", width="480", height="400")]
 
public class AnimationTest extends Sprite
{
	private var timeLine:Timeline;
	private var mainCircel:DisplayObject;
	private var animationManager:AnimationManager;
	private var helperManager:AnimationManager;
	private var subContiner:Sprite;
	private var inited:Boolean = false;
	private var isRunning:Boolean = false;;
 
	//==========================================================================
	//	Constuctor
	//==========================================================================
	public function AnimationTest()
	{
		stage.scaleMode = StageScaleMode.NO_SCALE;
		stage.align = StageAlign.TOP_LEFT;
 
		subContiner = new Sprite();
		addChild(subContiner);
 
		mainCircel = createCircel();
		addChild(mainCircel);
 
		Global.stage = this.stage;
 
		helperManager = new AnimationManager();
		animationManager = new AnimationManager();
		animationManager.addEventListener(AnimationEvent.FINISH, onAnimationFinished);
		start();
 
		stage.addEventListener(MouseEvent.CLICK, onClick);
	}
 
	private function start():void
	{
		if(!inited)
		{
			applyMainAnimationOn(mainCircel);
			inited = true;
		}
		else
		{
			timeLine.play();
		}
		this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
		isRunning = true;
	}
 
	private function stop():void
	{
		this.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
		timeLine.stop();
		isRunning = false;
	}
 
 
	//==========================================================================
	//	Applay Animation on Display Object
	//==========================================================================
 
	private function applyMainAnimationOn(disp:DisplayObject):void
	{
		var path:Path = new Path();
		path.moveTo(disp.x, disp.y);
		path.curveTo(randomX(), randomY(), randomX(), randomY());
 
		timeLine = new Timeline(RenderMethod.ENTER_FRAME);
		timeLine.addEventListener(AnimationEvent.FINISH, onAnimationFinished);
		timeLine.addTween(new PathTween(disp, path, true, 1, 30, Transitions.SINE_IN_AND_OUT));
		timeLine.play();
	}
 
	private function applySubAnimationOn(disp:DisplayObject):void
	{
		animationManager.scale(disp, 2, 2, 600, Transitions.BACK_OUT);
		helperManager.alpha(disp, .05, 500, Transitions.LINEAR);
		helperManager.move(disp, randomX(), randomY(), 500, Transitions.ELASTIC_IN_AND_OUT);
	}
 
	//==========================================================================
	//	Event Handler
	//==========================================================================
 
	private function onAnimationFinished(e:AnimationEvent):void
	{
		if(!e.animTarget)
		{
			applyMainAnimationOn(mainCircel);
		}
		else
		{
			subContiner.removeChild(e.animTarget as DisplayObject);
		}
	}
 
	private function onEnterFrame(e:Event):void
	{
		if(Math.random()<.7)
			return;
		var circel:DisplayObject = createCircel(20, Math.random()*0xFFFFFF);
		circel.x = this.mainCircel.x;
		circel.y = this.mainCircel.y;
		subContiner.addChild(circel);
		applySubAnimationOn(circel);
	}
 
	private function onClick(e:MouseEvent):void
	{
		isRunning ? stop() : start();
	}
 
	//==========================================================================
	//	Helper Functions
	//==========================================================================
 
	private function randomX():Number
	{
		return Math.random()*stage.stageWidth;
	}
	private function randomY():Number
	{
		return Math.random()*stage.stageHeight;
	}
 
	private function createCircel(r:Number=20, c:Number=0xFFFFFF):DisplayObject
	{
		var shape:Shape = new Shape();
		var g:Graphics = shape.graphics;
		g.beginFill(c);
		g.drawCircle(0, 0, r);
		g.endFill();
		return shape;
	}
}
}