
Код:
package classes.movers
{
import classes.parsers.Easing;
import fl.transitions.Tween;
import flash.utils.*;
public class SmoothMover
{
private var tweenX, tweenY;
private var duration;
private var typeMotion;
private var object;
public function SmoothMover ( object, typeMotion, duration )
{
object.smoothX = object.x;
object.smoothY = object.y;
this.object = object;
this.typeMotion = typeMotion;
this.duration = duration;
tweenX = new Tween ( object, "x", typeMotion, object.x, object.smoothX, duration, false );
tweenY = new Tween ( object, "y", typeMotion, object.y, object.smoothY, duration, false );
setInterval ( move, 100 );
}
static public function add ( object, t:String, mot:String, duration:Number )
{
if (object.smoothMover == undefined)
{
object.smoothMover = new SmoothMover ( object, Easing.get ( t, mot ), duration );
}
}
private function move ()
{
if ( tweenX.isPlaying )
{
tweenX.continueTo ( object.smoothX, duration );
tweenY.continueTo ( object.smoothY, duration );
}
else
{
tweenX = new Tween ( object, "x", typeMotion, object.x, object.smoothX, duration, false );
tweenY = new Tween ( object, "y", typeMotion, object.y, object.smoothY, duration, false );
}
}
}
}