Tweening is actually pretty easy, you can do it without the TweenMax class. (Note this is untested code; I just wrote it up. May have compile errors.)
This will perform a linear interpolation to count up. (ie the amount will grow by the same amount each frame) You could easily provide a function that will do exponential growth or anything else you wanted. (See here.)Code:import flash.utils.getTimer; scoreStart:Number = 0; scoreCurrent:Number = 0; scoreGoal:Number = 0; startTime:Number = 0; setScore(4000); // ENTER_FRAME event handler function scoreInterpolate(event:Event) { var currentTime:Number = getTimer(); var durationTime:Number = 3000; var t:Number = (currentTime - startTime) / durationTime; if (t < 1) { // Not finished counting up; interpolate value scoreCurrent = linearInterpolate(t, scoreStart, scoreGoal); } else { // At or exceeded the maximum time // Set the score to the target and terminate the event scoreCurrent = scoreGoal; removeEventListener(Event.ENTER_FRAME, scoreInterpolate) } trace(scoreCurrent); } // Performs a linear interpolation between two values function linearInterpolate(t:Number, minVal:Number, maxVal:Number) : Number { return minVal + t * (maxVal - minVal); } // Invokes an ENTER_FRAME event handler that will count up scoreCurrent to the provided goal function setScore(newScore:Number) { scoreStart = scoreCurrent; scoreGoal = newScore; startTime = getTimer(); addEventListener(Event.ENTER_FRAME, scoreInterpolate); }




Reply With Quote
