Posted By

adehaas on 03/15/13


Tagged


Versions (?)

HNK_Clock_Digits


 / Published in: ActionScript
 

  1. package nl.hnk.animations
  2. {
  3. import com.greensock.TweenLite;
  4. import com.greensock.easing.Linear;
  5.  
  6. import flash.display.Sprite;
  7. import flash.text.TextField;
  8.  
  9. /**
  10. * @author alexanderdehaas
  11. */
  12. public class ActiveClock extends Sprite
  13. {
  14. private var day1:TextField;
  15. private var day2:TextField;
  16. private var days:Array = [];
  17. private var targetValues:Array = [3, 7];
  18. public var currentValue:int = 0;
  19. private var slice:String;
  20.  
  21. public function ActiveClock()
  22. {
  23. with(graphics)
  24. {
  25. beginFill(0x666666);
  26. drawRect(0, 0, 300, 120);
  27. endFill();
  28. }
  29.  
  30. day1 = new TextField();
  31. day1.textColor = 0xFFFFFF;
  32. day1.text = '9';
  33. addChild(day1);
  34.  
  35. day2 = new TextField();
  36. day2.textColor = 0xFFFFFF;
  37. day2.text = '9';
  38. day2.x = 50;
  39. addChild(day2);
  40.  
  41. days.push(day1, day2);
  42. }
  43.  
  44. public function play():void
  45. {
  46. var delay:Number = 0.5;
  47. for(var i:int = 0; i < days.length; i++)
  48. {
  49. delay += 0.5;
  50. currentValue = 100;
  51. TweenLite.to(this, 2, {delay: delay, currentValue: targetValues[days.indexOf(days[i])], onUpdate: updateVal, onUpdateParams:[days[i]], ease:Linear.easeNone, overwrite: false});
  52. }
  53. }
  54.  
  55. private function updateVal(day:TextField):void
  56. {
  57. slice = String(currentValue);
  58. day.text = slice.slice(-1).toString();
  59. }
  60. }
  61. }

Report this snippet  

You need to login to post a comment.