DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Actionscript _Animate Class

02.13.2007
| 5378 views |
  • submit to reddit
        This is basically a way to set up an animation queue to utilize scripted tweening.  You would have to create external functions which carry forth the animation actions then store the function objects in the _Animate.queue Array in the sequence you wish to play them out.  Ideally, these functions would return a Tween object for the sake of utilizing "onMotionStopped".  Returning False (bool) will simply allow the next function in the queue to fire without checking for the onMotionStopped call.  When you are ready to start the animation sequence, just call launch();

import _String;

dynamic class _Animate {
	var queue:Array;
	
	function _Animate() {
		queue = null;
	}
	
	public function caller(qNum){
		var gA = this;
		var callback = queue[qNum].func.apply(this, _String.toArray(queue[qNum].params)); qNum++;
		if (qNum < queue.length && callback) callback.onMotionStopped = function() { gA.caller(qNum); }
		else if (qNum < queue.length && !callback) gA.caller(qNum);
	}
	
	public function launch(){ caller(0); }
	
	
}

Sample Usage

var zoomIn = new _Animate();

zoomIn.queue = [
	{func:aniSidebar, params:"hide,6"},
	{func:aniMapMidFade, params:"hide,6"}
];

zoomIn.launch();

function aniSidebar(action, time){
	var leftBeginX = (action == "hide") ? 0 : 0 - sidebarLeftBg._width;
	var leftEndX = (action == "hide") ? 0 - sidebarLeftBg._width : 0;
	var rightBeginX = (action == "hide") ? Stage.width - sidebarRightBg._width : Stage.width;
	var rightEndX = (action == "hide") ? Stage.width : Stage.width - sidebarRightBg._width;
	var transition = mx.transitions.easing.Regular.easeInOut;
	var leftAni = new mx.transitions.Tween(sidebarLeftBg, "_x", transition, leftBeginX, leftEndX, time);
	var rightAni = new mx.transitions.Tween(sidebarRightBg, "_x", transition, rightBeginX, rightEndX, time);
	return rightAni;
}

function aniMapMidFade(action, time){
	var begin = (action == "hide") ? 100 : 0;
	var end = (action == "hide") ? 0 : 100;
	var transition = mx.transitions.easing.Regular.easeOut;
	var mapMidAni = new mx.transitions.Tween(mapMid, "_alpha", transition, begin, end, time);
	return mapMidAni;
}