Posted By


julespong on 07/13/11

Tagged


Statistics


Viewed 232 times
Favorited by 0 user(s)

AnimatedCubeMapFace.as


/ Published in: ActionScript 3
Save to your folder(s)



Copy this code and paste it in your HTML
  1. package
  2. {
  3. import com.greensock.TweenMax;
  4.  
  5. import flash.display.Bitmap;
  6. import flash.display.BitmapData;
  7. import flash.display.Sprite;
  8. import flash.events.TimerEvent;
  9. import flash.utils.Timer;
  10.  
  11. public class AnimatedCubeMapFace extends Sprite
  12. {
  13.  
  14. private var __bottom:Bitmap;
  15. private var __top:Bitmap;
  16. private var __bottomBmpData:BitmapData;
  17. private var __topBmpData:BitmapData;
  18. private var __animationDirection:int = 0;
  19. private var __toggleDirectionTimer:Timer;
  20. private var __snapshot:BitmapData;
  21.  
  22. public function get snapshot():BitmapData
  23. {
  24. if (__snapshot == null)
  25. {
  26. __snapshot = new BitmapData(this.width, this.height, false);
  27. }
  28. __snapshot.draw(this);
  29.  
  30. return __snapshot;
  31. }
  32.  
  33. public function animate(direction:int):void
  34. {
  35. __toggleDirectionTimer.reset();
  36.  
  37. if (direction == 1)
  38. {
  39. __animationDirection = 1;
  40. TweenMax.to(__top, 1, { autoAlpha:1, onComplete:animationComplete });
  41. }
  42. else
  43. {
  44. __animationDirection = -1;
  45. TweenMax.to(__top, 1, { autoAlpha:0, onComplete:animationComplete });
  46. }
  47. }
  48.  
  49. private function animationComplete():void
  50. {
  51. __toggleDirectionTimer.start();
  52. }
  53.  
  54. public function AnimatedCubeMapFace(bottomBmpData:BitmapData, topBmpData:BitmapData)
  55. {
  56. super();
  57.  
  58. __bottomBmpData = bottomBmpData;
  59. __topBmpData = topBmpData;
  60.  
  61. init();
  62. initAnimation();
  63. }
  64.  
  65. private function initAnimation():void
  66. {
  67. __toggleDirectionTimer.start();
  68. }
  69.  
  70. private function init():void
  71. {
  72. __toggleDirectionTimer = new Timer(500, 1);
  73. __toggleDirectionTimer.addEventListener(TimerEvent.TIMER_COMPLETE, toggleDirectionTimerComplete, false, 0, true);
  74.  
  75. __bottom = new Bitmap(__bottomBmpData);
  76. addChild(__bottom);
  77.  
  78. __top = new Bitmap(__topBmpData);
  79. addChild(__top);
  80. }
  81.  
  82. protected function toggleDirectionTimerComplete(event:TimerEvent):void
  83. {
  84. if (__animationDirection == 0)
  85. {
  86. animate(-1);
  87. }
  88. else
  89. {
  90. animate(-__animationDirection);
  91. }
  92. }
  93.  
  94. }
  95. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.