Create An Apple Style Preloader Using A Custon Class

Steven sacks just posted custom class that creates an Apple style preloader.  It’s a simple class that uses the Flash Drawing API which makes it light and efficient. Check it out below.

package net.stevensacks.preloaders
{
	package net.stevensacks.preloaders
	{
		import flash.events.TimerEvent;
		import flash.display.Sprite;
		import flash.display.Shape;
		import flash.utils.Timer;

		public class CircleSlicePreloader extends Sprite
		{
			private var timer:Timer = new Timer(65);
			private static const SLICE_COUNT:int = 12;
			private static const RADIUS:int = 6;

			public function CircleSlicePreloader()
			{
				super();
				draw();
				timer.addEventListener(TimerEvent.TIMER, onTimer, false, 0, true);
				timer.start();
			}

			private function onTimer(event:TimerEvent):void
			{
				rotation = (rotation + (360 / SLICE_COUNT)) % 360;
			}

			private function draw():void
			{
				var i:int = SLICE_COUNT;
				var degrees:int = 360 / SLICE_COUNT;
				while (i--)
				{
					var slice:Shape = getSlice();
					slice.alpha = Math.max(0.2, 1 - (0.1 * i));
					var radianAngle:Number = (degrees * i) * Math.PI / 180;
					slice.rotation = -degrees * i;
					slice.x = Math.sin(radianAngle) * RADIUS;
					slice.y = Math.cos(radianAngle) * RADIUS;
					addChild(slice);
				}
			}

			private function getSlice():Shape
			{
				var slice:Shape = new Shape();
				slice.graphics.beginFill(0x666666);
				slice.graphics.drawRoundRect(-1, 0, 2, 6, 12, 12);
				slice.graphics.endFill();
				return slice;
			}
		}
	}
}

Additional Resources: