/* * Copyright 2008 (c) Lance Pollard * www.systemsofseven.com/blog * www.4ddesignlab.com * LanceJPollard@gmail.com * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, * copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following * conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. */ package com.fourD.layouts { import com.fourD.animators.TweenMaxAnimator; import flash.display.DisplayObject; import flash.geom.Point; import mx.components.baseClasses.GroupBase; import mx.core.ILayoutElement; import mx.core.IUIComponent; import mx.layout.LayoutBase; public class CircleLayout extends LayoutBase { public function CircleLayout() { super(); } public var rotate:Boolean = true; public function findIndexAt(children:Array, x:Number, y:Number):int { var hCenter:Number = target.width / 2; var vCenter:Number = target.height / 2; var angle:Number = Math.atan2(y-vCenter, x-hCenter) + Math.PI; var index:Number = angle * children.length / (2 * Math.PI) + 1; return index; } override public function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void { super.updateDisplayList(unscaledWidth, unscaledHeight); var layoutTarget:GroupBase = target; var layoutElement:ILayoutElement; var numOfItems:int = layoutTarget.numLayoutElements; var radius:Number = target.width - 10; var anglePer:Number = (Math.PI * 2) / numOfItems; var width:Number = target.width/2; var height:Number = target.height/2; var offset:Number = 180*(Math.PI/180); var rad:Number; var token:Object; for(var i:uint=0; i 180) { token.rotationY -= 360; } } animator.moveItem(layoutElement as DisplayObject, token); } //animator.end(); } } }