/ Published in: ActionScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
package nl.hnk.animations { import com.greensock.TweenLite; import com.greensock.easing.Linear; import flash.display.Sprite; import flash.text.TextField; /** * @author alexanderdehaas */ public class ActiveClock extends Sprite { private var day1:TextField; private var day2:TextField; private var days:Array = []; private var targetValues:Array = [3, 7]; public var currentValue:int = 0; private var slice:String; public function ActiveClock() { with(graphics) { beginFill(0x666666); drawRect(0, 0, 300, 120); endFill(); } day1 = new TextField(); day1.textColor = 0xFFFFFF; day1.text = '9'; addChild(day1); day2 = new TextField(); day2.textColor = 0xFFFFFF; day2.text = '9'; day2.x = 50; addChild(day2); days.push(day1, day2); } public function play():void { var delay:Number = 0.5; for(var i:int = 0; i < days.length; i++) { delay += 0.5; currentValue = 100; TweenLite.to(this, 2, {delay: delay, currentValue: targetValues[days.indexOf(days[i])], onUpdate: updateVal, onUpdateParams:[days[i]], ease:Linear.easeNone, overwrite: false}); } } private function updateVal(day:TextField):void { slice = String(currentValue); day.text = slice.slice(-1).toString(); } } }