Return to Snippet

Revision: 48942
at July 13, 2011 05:09 by julespong


Initial Code
package
{
	import com.greensock.TweenMax;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	public class AnimatedCubeMapFace extends Sprite
	{
		
		private var __bottom:Bitmap;
		private var __top:Bitmap;
		private var __bottomBmpData:BitmapData;
		private var __topBmpData:BitmapData;
		private var __animationDirection:int = 0;
		private var __toggleDirectionTimer:Timer;
		private var __snapshot:BitmapData;
		
		public function get snapshot():BitmapData
		{
			if (__snapshot == null)
			{
				__snapshot = new BitmapData(this.width, this.height, false);
			}
			__snapshot.draw(this);
			
			return __snapshot;
		}
		
		public function animate(direction:int):void
		{
			__toggleDirectionTimer.reset();
			
			if (direction == 1)
			{
				__animationDirection = 1;
				TweenMax.to(__top, 1, { autoAlpha:1, onComplete:animationComplete });
			}
			else
			{
				__animationDirection = -1;
				TweenMax.to(__top, 1, { autoAlpha:0, onComplete:animationComplete });
			}
		}
		
		private function animationComplete():void
		{
			__toggleDirectionTimer.start();
		}
		
		public function AnimatedCubeMapFace(bottomBmpData:BitmapData, topBmpData:BitmapData)
		{
			super();
			
			__bottomBmpData = bottomBmpData;
			__topBmpData = topBmpData;
			
			init();
			initAnimation();
		}
		
		private function initAnimation():void
		{
			__toggleDirectionTimer.start();
		}
		
		private function init():void
		{
			__toggleDirectionTimer = new Timer(500, 1);
			__toggleDirectionTimer.addEventListener(TimerEvent.TIMER_COMPLETE, toggleDirectionTimerComplete, false, 0, true);
			
			__bottom = new Bitmap(__bottomBmpData);
			addChild(__bottom);
			
			__top = new Bitmap(__topBmpData);
			addChild(__top);
		}
		
		protected function toggleDirectionTimerComplete(event:TimerEvent):void
		{
			if (__animationDirection == 0)
			{
				animate(-1);
			}
			else
			{
				animate(-__animationDirection);
			}
		}
		
	}
}

Initial URL

                                

Initial Description

                                

Initial Title
AnimatedCubeMapFace.as

Initial Tags

                                

Initial Language
ActionScript 3