include "Math2.as" //圖片容器 var menu:Sprite=new Sprite(); //使圖標(biāo)移動(dòng) menu.x = 300; menu.y = 200; //注冊(cè)事件偵聽器 menu.addEventListener(Event.ENTER_FRAME,moveMenu); this.addChild(menu); //橢圓在x 和y 軸上的截距 var disx:Number = 200; var disy:Number = 10; //旋轉(zhuǎn)速度 var speed:Number = 0; initMenu(5); function initMenu(n:int) { for (var i:int; i<n; i++) { var mc:MovieClip = new IconMenu(); //縮小圖標(biāo) mc.scaleX = mc.scaleY = .5; menu.addChild(mc); } } //事件偵聽器函數(shù) function moveMenu(e:Event):void { //獲取圖標(biāo)數(shù) var iconCount:int = menu.numChildren; //定義數(shù)組 var depthArray:Array = new Array(); //把360度平分 var angle:Number = 360 / iconCount; for (var z:int; z<iconCount; z++) { //根據(jù)深度獲取圖標(biāo) var mc:MovieClip = menu.getChildAt(z); //跳轉(zhuǎn)到不同幀,來顯示不同的圖標(biāo) mc.gotoAndStop(z+1); //設(shè)置圖標(biāo)的位置 mc.x = cosD(speed + angle*z) * disx; mc.y = sinD(speed + angle*z) * disy; setProp(mc,"alpha"); setProp(mc,"scaleX",.2,.7); setProp(mc,"scaleY",.2,.7); //保存圖標(biāo)到數(shù)組 depthArray[z] = mc; } //重新設(shè)置圖標(biāo)的深度 arrange(depthArray); speed += 2; } function arrange(depthArray:Array):void { //按照y坐標(biāo)排序 depthArray.sortOn("y", Array.NUMERIC); var i:int = depthArray.length; while (i--) { menu.setChildIndex(depthArray[i], i); } } function setProp(mc:MovieClip,prop:String,n1:Number = .5, n2:Number = 1):void { mc[prop] = ((mc.y + 2 * disy) / disy - 1) / 2 * (n2 - n1) + n1; } |
5、新建.as文檔,保存名為:Math2.as (這個(gè)文檔是進(jìn)行三角函數(shù)的計(jì)算)
//角度轉(zhuǎn)弧度 function angleToRadian(angle:Number):Number { return angle*(Math.PI/180); } //弧度轉(zhuǎn)角度 function radianToAngle(radian:Number):Number { return radian*(180/Math.PI); } //計(jì)算正弦值 function sinD(angle:Number):Number { return Math.sin(angleToRadian(angle)); } //計(jì)算余弦值 function cosD(angle:Number):Number { return Math.cos(angleToRadian(angle)); } //計(jì)算反正切 function atan2D(y:Number, x:Number):Number { return radianToAngle(Math.atan2(y, x)); } |
把fla文檔與Math2.as 文檔保存在同一目錄下,進(jìn)行測(cè)試。
討論: http://www.missyuan.com/viewthread.php?tid=417566