//定義旋轉(zhuǎn)的最終角度
var endAngle:Number = 90;
//保存已經(jīng)旋轉(zhuǎn)的角度
var tempAngle:Number = 0;
//保存旋轉(zhuǎn)的狀態(tài)
var isRotating:Boolean = true;
//注冊圖標(biāo)的單擊事件
mc.addEventListener(MouseEvent.MOUSE_DOWN,startRotation);
//定義偵聽器函數(shù)
function startRotation(e:MouseEvent):void
{
//得到圖標(biāo)
var currentIcon::MovieClip = e.target;
//得到圖標(biāo)的角度
enaAngle = atan2D(currentIcon.y,cosD(currentIcon.angle) * disy);
//計(jì)算旋轉(zhuǎn)的度數(shù)
endAngle = (endAngle > -180&&endAngle < -90) ? - 270 - endAngle:90 - endAngle;
//單擊后旋轉(zhuǎn),需要注冊enterFrame事件偵聽器
menu.addEventListener(Event.ENTER_FRAME,moveMenu);
}
每次旋轉(zhuǎn)前要重新初始化旋轉(zhuǎn)角度
function initAngle(b:Boolean)
{
//如果處于旋轉(zhuǎn)狀態(tài)保存角度
if (isRotating)
//保存圖標(biāo)角度
tempAngle += speed;
//旋轉(zhuǎn)速度重新設(shè)置為0
speed = 0;
//設(shè)置旋轉(zhuǎn)狀態(tài)
isRotating = b;
}
修改函數(shù)moveMenu():
function moveMenu(e:Event):void
{
var iconCount:int = menu,numChildren;
var depthArrat:Array = new Array();
var angle:Number = 360 / iconCount;
for (var z:int; z < iconCount; z++)
{
var mc:MovieClip = menu.getChildAt(z);
mc.gotoAndStop(z + 1);
//把圖標(biāo)角度保存在mc的動態(tài)屬性中
mc.angle = tempAngle + speed + angle * z;
mc.x = cosD(mc.angle) * disy;
mc.y = sinD(mc.angle) * disy;
depthArray[z] = mc;
setProp(mc, "alpha");
setProp(mc, "scaleX", .2, .7);
setProp(mc, "scaleY", .2, .7);
}
arrange(depthArray);
//利用緩沖公式把圖標(biāo)旋轉(zhuǎn)到endAngle角度
speed += (endAngle - speed) * .2;
if (Math.abs(speed - endAngle) < 1)
{
//移除事件偵聽器
menu.removeEventListener(Event.ENTER_FRAME,moveMenu);
initAngle(false);
}
}
|