//定义旋转的最终角度
var endAngle:Number = 90;
//保存已经旋转的角度
var tempAngle:Number = 0;
//保存旋转的状态
var isRotating:Boolean = true;
//注册图标的单击事件
mc.addEventListener(MouseEvent.MOUSE_DOWN,startRotation);
//定义侦听器函数
function startRotation(e:MouseEvent):void
{
//得到图标
var currentIcon::MovieClip = e.target;
//得到图标的角度
enaAngle = atan2D(currentIcon.y,cosD(currentIcon.angle) * disy);
//计算旋转的度数
endAngle = (endAngle > -180&&endAngle < -90) ? - 270 - endAngle:90 - endAngle;
//单击后旋转,需要注册enterFrame事件侦听器
menu.addEventListener(Event.ENTER_FRAME,moveMenu);
}
每次旋转前要重新初始化旋转角度
function initAngle(b:Boolean)
{
//如果处于旋转状态保存角度
if (isRotating)
//保存图标角度
tempAngle += speed;
//旋转速度重新设置为0
speed = 0;
//设置旋转状态
isRotating = b;
}
修改函数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);
//把图标角度保存在mc的动态属性中
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);
//利用缓冲公式把图标旋转到endAngle角度
speed += (endAngle - speed) * .2;
if (Math.abs(speed - endAngle) < 1)
{
//移除事件侦听器
menu.removeEventListener(Event.ENTER_FRAME,moveMenu);
initAngle(false);
}
}
|