Mac style preloader in ActionScript3

Hi there,

I just wanted to share a nice AS3 class I found at steven sacks blog, which produce Mac style loading animation. You may find it interesting when implementing preloader in your AS3 application 😉

Sample swf

This movie requires Flash Player 8

AS3 Class code:

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 var slices:int;
                private var radius:int;
 
                public function CircleSlicePreloader(slices:int = 12, radius:int = 6)
                {
                        super();
                        this.slices = slices;
                        this.radius= radius;
                        draw();
                        timer.addEventListener(TimerEvent.TIMER, onTimer, false, 0, true);
                        timer.start();
                }
                private function onTimer(event:TimerEvent):void
                {
                        rotation = (rotation + (360 / slices)) % 360;
                }
                private function draw():void
                {
                        var i:int = slices;
                        var degrees:int = 360 / slices;
                        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;
                }
        }
}

Related Resources.

0 Responses to “Mac style preloader in ActionScript3”


  1. No Comments

Leave a Reply