Flash banner tween code snippet.


Even in 2014 there's still flash banners around, and the bytesizes are as small as they always were. I've gotten used to the syntax of TweenLite, but even the TweenNano is buggy and takes several kb of space. 

However, if you use the built in tweener that were introduced in flash 8, most of the basic function can be utilized, so I wrote this simple function to mimic the syntax for simple property animations like TweenLite, hense the name, TweenLike.

Usage: TweenLike(mc,.3,{_y:200,ease:Bounce.easeOut,onComplete:function(){trace("done")}});

Limitations:
It's written in as2 since banners seem to like version 8 and as2 click event when opening popup windows. They still seem to be blocked in as3 if you haven't written a lot of extra code to circumvent the limitation and even then you're not garanteed it'll work.

//code start


function TweenLike(target,time,obj){
/*
Usage: TweenLike(mc,.3,{_y:200,ease:Bounce.easeOut,onComplete:function(){trace("done")}});
Remember to import
import mx.transitions.Tween;
import mx.transitions.easing.*;

available eases are (in easeInOut,easeOut,easeIn,easeNone as well):
Back
Bounce
Elastic
Regular
Strong
None
*/
var prop;
var from;
var to;
var delay = 0;
var complete;
var easing = Regular.easeOut;
for(var objprop in obj){
if(objprop.indexOf("_") != -1){
prop = objprop.toString();
to = obj[objprop];
var targetname = target.toString();
switch(objprop){
case "_x":
from = target._x;
break;
case "_y":
from = target._y;
break;
case "_xscale":
from = target._xscale;
break;
case "_yscale":
from = target._yscale;
break;
case "_alpha":
from = target._alpha;
case "_rotation":
from = target._alpha;
break;
}
}
if(objprop == "ease"){
easing = obj[objprop];
}
if(objprop == "delay"){
delay = obj[objprop];
}
if(objprop == "onComplete"){
complete = obj[objprop];
}
//end
}
if(delay != 0){
setTimeout(function(){
var propTween:Tween = new mx.transitions.Tween (target,prop,easing,from,to,time,true);
},delay*1000);
if(complete != undefined){
propTween.onMotionFinished = complete();
}
}else{
var propTween:Tween = new mx.transitions.Tween (target,prop,easing,from,to,time,true);
propTween.onMotionFinished = complete();
}
}

 

//code end