forked from: circle menu buttons

by bradsedito forked from circle menu buttons (diff: 11)
...
@author arithma
♥1 | Line 48 | Modified 2011-02-26 00:46:29 | MIT License
play

ActionScript3 source code

/**
 * Copyright bradsedito ( http://wonderfl.net/user/bradsedito )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/nL34
 */

// forked from arithma's circle menu buttons
package 
{
    import caurina.transitions.Tweener;
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.geom.ColorTransform;
    
    /**
     * ...
     * @author arithma
     */
    public class CircleMenu extends Sprite 
    {
        private var buttons:Array;
        public function CircleMenu() {
            buttons = new Array();
            for (var i:int = 0; i < 5; i++) {
                var button:Sprite = new Sprite();
                button.graphics.beginFill(0);
                button.graphics.drawRoundRect( -30, - 100, 60, 16, 5, 5);
                button.graphics.endFill();
                
                buttons.push(button);
                button.x = stage.stageWidth * .5;
                button.y = stage.stageHeight * .5;
                addChild(button);
                button.buttonMode = true;
                
                button.rotation = 360 / 5 * i;
                
                button.addEventListener(MouseEvent.MOUSE_OVER, buttonClick);
            }
        }
        
        private function buttonClick(e:MouseEvent):void {
            var index:int = buttons.indexOf(e.currentTarget);
            var center:Number = 360 / 5 * index;
            while (center - buttons[index].rotation > 180)
                center -= 360;
            while (center - buttons[index].rotation < -180)
                center += 360;
            Tweener.addTween(buttons[index], { rotation:center, time:1, scaleY:1.1 } );
            buttons[index].transform.colorTransform = new ColorTransform(0, 0, 0, 1, 0xFF, 0x66);
            for (var i:int = index + 1; i < index + 12; i++) {
                var r:int = i % 5;
                r = (r - index) % 5;
                var rot:Number = (360 / 6 * (r + ((r > 0)?.5: -.5)) + center);
                while (rot - buttons[i % 12].rotation > 180)
                    rot -= 360;
                while (rot - buttons[i % 5].rotation < -180)
                    rot += 360;
                Tweener.addTween(buttons[i%5], { rotation:rot, scaleY:1, time:1 } );
                buttons[i%5].transform.colorTransform = new ColorTransform();
            }
        }
    }
    
}