flash as3.0 3D旋转菜单问题
http://www.missyuan.com/viewthread.php?tid=417566&extra=&page=1http://zhidao.baidu.co...
http://www.missyuan.com/viewthread.php?tid=417566&extra=&page=1
http://zhidao.baidu.com/question/466773108.html
一样的问题 代码弄好了测试成功了 但是只有5张图片 如果要加10张呢 ?
include "Math2.as"
//图片容器
var menu:Sprite=new Sprite();
//使图标移动
menu.x = 300;
menu.y = 200;
//注册事件侦听器
menu.addEventListener(Event.ENTER_FRAME,moveMenu);
this.addChild(menu);
//椭圆在x 和y 轴上的截距
var disx:Number = 200;
var disy:Number = 10;
//旋转速度
var speed:Number = 0;
initMenu(5);
function initMenu(n:int) {
for (var i:int; i<n; i++) {
var mc:MovieClip = new IconMenu();
//缩小图标
mc.scaleX = mc.scaleY = .5;
menu.addChild(mc);
}
}
//事件侦听器函数
function moveMenu(e:Event):void {
//获取图标数
var iconCount:int = menu.numChildren;
//定义数组
var depthArray:Array = new Array();
//把360度平分
var angle:Number = 360 / iconCount;
for (var z:int; z<iconCount; z++) {
//根据深度获取图标
var mc:MovieClip = menu.getChildAt(z);
//跳转到不同帧,来显示不同的图标
mc.gotoAndStop(z+1);
//设置图标的位置
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);
//保存图标到数组
depthArray[z] = mc;
}
//重新设置图标的深度
arrange(depthArray);
speed += 2;
}
function arrange(depthArray:Array):void {
//按照y坐标排序
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;
} 展开
http://zhidao.baidu.com/question/466773108.html
一样的问题 代码弄好了测试成功了 但是只有5张图片 如果要加10张呢 ?
include "Math2.as"
//图片容器
var menu:Sprite=new Sprite();
//使图标移动
menu.x = 300;
menu.y = 200;
//注册事件侦听器
menu.addEventListener(Event.ENTER_FRAME,moveMenu);
this.addChild(menu);
//椭圆在x 和y 轴上的截距
var disx:Number = 200;
var disy:Number = 10;
//旋转速度
var speed:Number = 0;
initMenu(5);
function initMenu(n:int) {
for (var i:int; i<n; i++) {
var mc:MovieClip = new IconMenu();
//缩小图标
mc.scaleX = mc.scaleY = .5;
menu.addChild(mc);
}
}
//事件侦听器函数
function moveMenu(e:Event):void {
//获取图标数
var iconCount:int = menu.numChildren;
//定义数组
var depthArray:Array = new Array();
//把360度平分
var angle:Number = 360 / iconCount;
for (var z:int; z<iconCount; z++) {
//根据深度获取图标
var mc:MovieClip = menu.getChildAt(z);
//跳转到不同帧,来显示不同的图标
mc.gotoAndStop(z+1);
//设置图标的位置
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);
//保存图标到数组
depthArray[z] = mc;
}
//重新设置图标的深度
arrange(depthArray);
speed += 2;
}
function arrange(depthArray:Array):void {
//按照y坐标排序
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;
} 展开
2013-02-05
展开全部
例如:1、新建Flash文件,设置宽、高属性为 550 × 400 。
2、用圆角矩形工具,画一个 158 × 35的长方形。笔触为8白色,填充色#0 F7E 88。图1
3、将长方形转换成名为 " Menu Item " 的影片剪辑。设定注册点为中心。图2
4、双击舞台上的影片剪辑,进入编辑状态。创建动态文本,在它里面输入需要的本文。图3
5、在属性面板中输入实例名字 " menuItemText" 。
6、按下字符嵌入按钮,插入下列字型。图4
7、切换回主场景1,删除舞台上的影片剪辑,实例将由代码生成。
8、打开库元件面板,右键单击影片剪辑,(CS3选链接、CS4选属性)给元件添加一个绑定类。类名 " MenuItem" 。图5
9、选中第1帧,打开动作面板输入代码://The total number of menu items
const NUMBER_OF_ITEMS:uint = 20;
//This array will contain all the menu items
var menuItems:Array = new Array();
//Set the focal length
var focalLength:Number = 350;
//Set the vanishing point
var vanishingPointX:Number = stage.stageWidth / 2;
var vanishingPointY:Number = stage.stageHeight / 2;
//We calculate the angleSpeed in the ENTER_FRAME listener
var angleSpeed:Number = 0;
//Radius of the circle
var radius:Number = 128;
//Calculate the angle difference between the menu items (in radians)
var angleDifference:Number = Math.PI * (360 / NUMBER_OF_ITEMS) / 180;
//This loop creates and positions the carousel items
for (var i:uint = 0; i < NUMBER_OF_ITEMS; i++) {
//Create a new menu item
var menuItem:MenuItem = new MenuItem();
//Calculate the starting angle for the menu item
var startingAngle:Number = angleDifference * i;
//Set a "currentAngle" attribute for the menu item
menuItem.currentAngle = startingAngle;
//Position the menu item
menuItem.xpos3D = - radius * Math.cos(menuItem.currentAngle) * 0.5;
menuItem.ypos3D = radius * Math.sin(startingAngle);
menuItem.zpos3D = radius * Math.cos(startingAngle);
//Calculate the scale ratio for the menu item (the further the item -> the smaller the scale ratio)
var scaleRatio = focalLength/(focalLength + menuItem.zpos3D);
//Scale the menu item according to the scale ratio
menuItem.scaleX = menuItem.scaleY = scaleRatio;
//Position the menu item to the stage (from 3D to 2D coordinates)
menuItem.x = vanishingPointX + menuItem.xpos3D * scaleRatio;
menuItem.y = vanishingPointY + menuItem.ypos3D * scaleRatio;
//Assign an initial alpha
menuItem.alpha = 0.3;
//Add a text to the menu item
menuItem.menuItemText.text = "Menu item " + i;
//We don't want the text field to catch mouse events
menuItem.mouseChildren = false;
//Assign MOUSE_OVER, MOUSE_OUT and CLICK listeners for the menu item
menuItem.addEventListener(MouseEvent.MOUSE_OVER, mouseOverItem);
menuItem.addEventListener(MouseEvent.MOUSE_OUT, mouseOutItem);
menuItem.addEventListener(MouseEvent.CLICK, itemClicked);
//Add the menu item to the menu items array
menuItems.push(menuItem);
//Add the menu item to the stage
addChild(menuItem);
}
//Add an ENTER_FRAME listener for the animation
addEventListener(Event.ENTER_FRAME, moveCarousel);
//This function is called in each frame
function moveCarousel(e:Event):void {
//Calculate the angle speed according to mouseY position
angleSpeed = (mouseY - stage.stageHeight / 2) * 0.0002;
//Loop through the menu items
for (var i:uint = 0; i < NUMBER_OF_ITEMS; i++) {
//Store the menu item to a local variable
var menuItem:MenuItem = (MenuItem)(menuItems);
//Update the current angle of the item
menuItem.currentAngle += angleSpeed;
//Calculate a scale ratio
var scaleRatio = focalLength/(focalLength + menuItem.zpos3D);
//Scale the item according to the scale ratio
menuItem.scaleX=menuItem.scaleY=scaleRatio;
//Set new 3D coordinates
menuItem.xpos3D=- radius*Math.cos(menuItem.currentAngle)*0.5;
menuItem.ypos3D=radius*Math.sin(menuItem.currentAngle);
menuItem.zpos3D=radius*Math.cos(menuItem.currentAngle);
//Update the item's coordinates.
menuItem.x=vanishingPointX+menuItem.xpos3D*scaleRatio;
menuItem.y=vanishingPointY+menuItem.ypos3D*scaleRatio;
}
//Call the function that sorts the items so they overlap each other correctly
sortZ();
}
//This function sorts the items so they overlap each other correctly
function sortZ():void {
//Sort the array so that the item which has the highest
//z position (= furthest away) is first in the array
menuItems.sortOn("zpos3D", Array.NUMERIC | Array.DESCENDING);
//Set new child indexes for the images
for (var i:uint = 0; i < NUMBER_OF_ITEMS; i++) {
setChildIndex(menuItems, i);
}
}
//This function is called when a mouse is over an item
function mouseOverItem(e:Event):void {
//Change the alpha to 1
e.target.alpha=1;
}
//This function is called when a mouse is out of an item
function mouseOutItem(e:Event):void {
//Change the alpha to 1
e.target.alpha=0.3;
}
//This function is called when an item is clicked
function itemClicked(e:Event):void {
trace("Item clicked! Add your own logic here.");
}10、完成,测试你的影片。
(不知我回答得对不对?希望互相指教,多谢!)
2、用圆角矩形工具,画一个 158 × 35的长方形。笔触为8白色,填充色#0 F7E 88。图1
3、将长方形转换成名为 " Menu Item " 的影片剪辑。设定注册点为中心。图2
4、双击舞台上的影片剪辑,进入编辑状态。创建动态文本,在它里面输入需要的本文。图3
5、在属性面板中输入实例名字 " menuItemText" 。
6、按下字符嵌入按钮,插入下列字型。图4
7、切换回主场景1,删除舞台上的影片剪辑,实例将由代码生成。
8、打开库元件面板,右键单击影片剪辑,(CS3选链接、CS4选属性)给元件添加一个绑定类。类名 " MenuItem" 。图5
9、选中第1帧,打开动作面板输入代码://The total number of menu items
const NUMBER_OF_ITEMS:uint = 20;
//This array will contain all the menu items
var menuItems:Array = new Array();
//Set the focal length
var focalLength:Number = 350;
//Set the vanishing point
var vanishingPointX:Number = stage.stageWidth / 2;
var vanishingPointY:Number = stage.stageHeight / 2;
//We calculate the angleSpeed in the ENTER_FRAME listener
var angleSpeed:Number = 0;
//Radius of the circle
var radius:Number = 128;
//Calculate the angle difference between the menu items (in radians)
var angleDifference:Number = Math.PI * (360 / NUMBER_OF_ITEMS) / 180;
//This loop creates and positions the carousel items
for (var i:uint = 0; i < NUMBER_OF_ITEMS; i++) {
//Create a new menu item
var menuItem:MenuItem = new MenuItem();
//Calculate the starting angle for the menu item
var startingAngle:Number = angleDifference * i;
//Set a "currentAngle" attribute for the menu item
menuItem.currentAngle = startingAngle;
//Position the menu item
menuItem.xpos3D = - radius * Math.cos(menuItem.currentAngle) * 0.5;
menuItem.ypos3D = radius * Math.sin(startingAngle);
menuItem.zpos3D = radius * Math.cos(startingAngle);
//Calculate the scale ratio for the menu item (the further the item -> the smaller the scale ratio)
var scaleRatio = focalLength/(focalLength + menuItem.zpos3D);
//Scale the menu item according to the scale ratio
menuItem.scaleX = menuItem.scaleY = scaleRatio;
//Position the menu item to the stage (from 3D to 2D coordinates)
menuItem.x = vanishingPointX + menuItem.xpos3D * scaleRatio;
menuItem.y = vanishingPointY + menuItem.ypos3D * scaleRatio;
//Assign an initial alpha
menuItem.alpha = 0.3;
//Add a text to the menu item
menuItem.menuItemText.text = "Menu item " + i;
//We don't want the text field to catch mouse events
menuItem.mouseChildren = false;
//Assign MOUSE_OVER, MOUSE_OUT and CLICK listeners for the menu item
menuItem.addEventListener(MouseEvent.MOUSE_OVER, mouseOverItem);
menuItem.addEventListener(MouseEvent.MOUSE_OUT, mouseOutItem);
menuItem.addEventListener(MouseEvent.CLICK, itemClicked);
//Add the menu item to the menu items array
menuItems.push(menuItem);
//Add the menu item to the stage
addChild(menuItem);
}
//Add an ENTER_FRAME listener for the animation
addEventListener(Event.ENTER_FRAME, moveCarousel);
//This function is called in each frame
function moveCarousel(e:Event):void {
//Calculate the angle speed according to mouseY position
angleSpeed = (mouseY - stage.stageHeight / 2) * 0.0002;
//Loop through the menu items
for (var i:uint = 0; i < NUMBER_OF_ITEMS; i++) {
//Store the menu item to a local variable
var menuItem:MenuItem = (MenuItem)(menuItems);
//Update the current angle of the item
menuItem.currentAngle += angleSpeed;
//Calculate a scale ratio
var scaleRatio = focalLength/(focalLength + menuItem.zpos3D);
//Scale the item according to the scale ratio
menuItem.scaleX=menuItem.scaleY=scaleRatio;
//Set new 3D coordinates
menuItem.xpos3D=- radius*Math.cos(menuItem.currentAngle)*0.5;
menuItem.ypos3D=radius*Math.sin(menuItem.currentAngle);
menuItem.zpos3D=radius*Math.cos(menuItem.currentAngle);
//Update the item's coordinates.
menuItem.x=vanishingPointX+menuItem.xpos3D*scaleRatio;
menuItem.y=vanishingPointY+menuItem.ypos3D*scaleRatio;
}
//Call the function that sorts the items so they overlap each other correctly
sortZ();
}
//This function sorts the items so they overlap each other correctly
function sortZ():void {
//Sort the array so that the item which has the highest
//z position (= furthest away) is first in the array
menuItems.sortOn("zpos3D", Array.NUMERIC | Array.DESCENDING);
//Set new child indexes for the images
for (var i:uint = 0; i < NUMBER_OF_ITEMS; i++) {
setChildIndex(menuItems, i);
}
}
//This function is called when a mouse is over an item
function mouseOverItem(e:Event):void {
//Change the alpha to 1
e.target.alpha=1;
}
//This function is called when a mouse is out of an item
function mouseOutItem(e:Event):void {
//Change the alpha to 1
e.target.alpha=0.3;
}
//This function is called when an item is clicked
function itemClicked(e:Event):void {
trace("Item clicked! Add your own logic here.");
}10、完成,测试你的影片。
(不知我回答得对不对?希望互相指教,多谢!)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询