Actionscript:
-
var box:MovieClip = new MovieClip();
-
box.graphics.beginFill(0xFF0000);
-
box.graphics.drawRect(-25,-25,50,50);
-
addChild(box);
-
-
stage.addEventListener(MouseEvent.CLICK, onStageDown);
-
function onStageDown(evt:MouseEvent):void{
-
moveTo(box, "x", 300, 2, Back.easeOut);
-
moveTo(box, "y", 200, 2, Back.easeOut);
-
moveTo(box, "scaleX", 2, 2, Back.easeOut);
-
moveTo(box, "rotation", 180, 2, Quartic.easeOut, onDone);
-
stage.removeEventListener(MouseEvent.CLICK, onStageDown);
-
}
-
-
function onDone():void {
-
moveTo(box, "x", 120, 2, Back.easeIn);
-
}
-
-
//
-
// -- TWEEN ENGINE
-
//
-
import fl.motion.easing.*;
-
-
// movieClip to tween, property to tween, final value for the property, duration of tween,
-
// ease type, complete callback function
-
function moveTo(mc:MovieClip, prop:String, dest:Number, duration:Number, ease=null,
-
completeFunction:Function=null):void {
-
if (ease == null) {
-
ease = Quartic.easeOut;
-
}
-
// use the property to make all var names unique
-
mc["begin" + prop] = mc[prop];
-
mc["change" + prop] = dest - mc[prop];
-
mc["time" + prop] = 0;
-
mc["startTime" + prop] = getTimer();
-
mc["duration" + prop] = duration;
-
mc["prop"] = prop;
-
mc["ease" + prop] = ease;
-
mc["complete_" + prop] = completeFunction;
-
mc.addEventListener(Event.ENTER_FRAME, makeMotionFunction(mc, prop));
-
}
-
-
function makeMotionFunction(mc:MovieClip, prop:String):Function {
-
return function(evt:Event){
-
if (mc["time" +prop] <= mc["duration"+ prop]){
-
mc[prop]=mc["ease" + prop](mc["time" + prop], mc["begin" +prop], mc["change"+ prop], mc["duration"+ prop]);
-
} else {
-
var completeFunction:Function = mc["complete_"+prop];
-
if (completeFunction!=null){
-
completeFunction();
-
}
-
mc.removeEventListener(Event.ENTER_FRAME, arguments.callee);
-
// see how long the tween took
-
//trace(mc["time"+prop]);
-
}
-
mc["time" + prop] = (getTimer() - mc["startTime" + prop]) / 1000;
-
};
-
}
-
/*
-
WARNING: This code was written for fun. Use at your own risk.
-
*/
This code uses a ~35 line tweening engine. I wrote this for fun a few weeks back. It works by creating dynamic variables on the MovieClip that it tweens. The dynamic variables and the square bracket syntax cause it to be pretty slow. Definitely not a substitute for a real tweening engine... like TweenLite.
I wouldn't recommend using this for anything other than playing around. See warning page for more info.