Speed and Spring
Back in the Flash 5 days, before tweening engines and Robert Penner's easing functions, flash developers used a "dirty" way of tweening through code.
The reason why this was dirty was because in all actuality, the object never completely arrives to it's designation, only fractions upon fractions to being so close to it that the user couldn't tell the difference. Here's a quick little way of remembering how to do that. The following code uses speed and spring.
var destX:int = 500; var speed:Number = 0.5; var spring:Number = 0.5; var curX:Number = 0; var velX:Number = 0; stage.addEventListener (Event.ENTER_FRAME, moveBox); function moveBox (e:Event):void { velX = ((destX - curX) * speed) + (velX * spring); curX += velX; // this kills the enter frame if the object gets close enough if (Number(Math.abs(velX).toFixed(2))<0.01) { trace ('done'); velX=0; curX=destX; stage.removeEventListener (Event.ENTER_FRAME, moveBox); } your_object.x=curX; }
I'll further explain the code (and math) once I get a chance to.
No comments yet