版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、AS3.0 3D旋转木马效果实例在这个 3D旋转菜单教程中,将学习如何用 AS3 代码创建一个垂直的 3D立体菜单效果。木马将会根据鼠标决定旋转速度。演示:1、新建Flash文件,设置宽、高属性为 550 400 。2、用圆角矩形工具,画一个 158 35的长方形。笔触为8白色,填充色0 F7E 88。图1下载 (22.67 KB)2010-3-17 08:203、将长方形转换成名为 Menu Item 的影片剪辑。设定注册点为中心。图2下载 (15.34 KB)2010-3-17 08:204、双击舞台上的影片剪辑,进入编辑状态。创建动态文本,在它里面输入需要的本文。图3下载 (7.57 K
2、B)2010-3-17 08:205、在属性面板中输入实例名字 menuItemText 。6、按下字符嵌入按钮,插入下列字型。图4下载 (44.37 KB)2010-3-17 08:207、切换回主场景1,删除舞台上的影片剪辑,实例将由代码生成。8、打开库元件面板,右键单击影片剪辑,(CS3选链接、CS4选属性)给元件添加一个绑定类。类名 MenuItem 。图5下载 (23.04 KB)2010-3-17 08:209、选中第1帧,打开动作面板输入代码: 1. /The total number of menu items2. const NUMBER_OF_ITEMS:uint = 20
3、;3.4. /This array will contain all the menu items5. var menuItems:Array = new Array();6.7. /Set the focal length8. var focalLength:Number = 350;9.10. /Set the vanishing point11. var vanishingPointX:Number = stage.stageWidth / 2;12. var vanishingPointY:Number = stage.stageHeight / 2;13.14. /We calcul
4、ate the angleSpeed in the ENTER_FRAME listener15. var angleSpeed:Number = 0;16.17. /Radius of the circle18. var radius:Number = 128;19.20. /Calculate the angle difference between the menu items (in radians)21. var angleDifference:Number = Math.PI * (360 / NUMBER_OF_ITEMS) / 180;22.23. /This loop cre
5、ates and positions the carousel items24. for (var i:uint = 0; i the smaller the scale ratio)41. var scaleRatio = focalLength/(focalLength + menuItem.zpos3D);42.43. /Scale the menu item according to the scale ratio44. menuItem.scaleX = menuItem.scaleY = scaleRatio;45.46. /Position the menu item to th
6、e stage (from 3D to 2D coordinates)47. menuItem.x = vanishingPointX + menuItem.xpos3D * scaleRatio;48. menuItem.y = vanishingPointY + menuItem.ypos3D * scaleRatio;49.50. /Assign an initial alpha51. menuItem.alpha = 0.3;52.53. /Add a text to the menu item54. menuItem.menuItemText.text = Menu item + i
7、;55.56. /We dont want the text field to catch mouse events57. menuItem.mouseChildren = false;58.59. /Assign MOUSE_OVER, MOUSE_OUT and CLICK listeners for the menu item60. menuItem.addEventListener(MouseEvent.MOUSE_OVER, mouseOverItem);61. menuItem.addEventListener(MouseEvent.MOUSE_OUT, mouseOutItem)
8、;62. menuItem.addEventListener(MouseEvent.CLICK, itemClicked);63.64. /Add the menu item to the menu items array65. menuItems.push(menuItem);66.67. /Add the menu item to the stage68. addChild(menuItem);69. 70.71. /Add an ENTER_FRAME listener for the animation72. addEventListener(Event.ENTER_FRAME, mo
9、veCarousel);73.74. /This function is called in each frame75. function moveCarousel(e:Event):void 76.77. /Calculate the angle speed according to mouseY position78. angleSpeed = (mouseY - stage.stageHeight / 2) * 0.0002;79.80. /Loop through the menu items81. for (var i:uint = 0; i NUMBER_OF_ITEMS; i+)
10、 82.83. /Store the menu item to a local variable84. var menuItem:MenuItem = (MenuItem)(menuItemsi);85.86. /Update the current angle of the item87. menuItem.currentAngle += angleSpeed;88.89. /Calculate a scale ratio90. var scaleRatio = focalLength/(focalLength + menuItem.zpos3D);91.92. /Scale the ite
11、m according to the scale ratio93. menuItem.scaleX=menuItem.scaleY=scaleRatio;94.95. /Set new 3D coordinates96. menuItem.xpos3D=- radius*Math.cos(menuItem.currentAngle)*0.5;97. menuItem.ypos3D=radius*Math.sin(menuItem.currentAngle);98. menuItem.zpos3D=radius*Math.cos(menuItem.currentAngle);99.100. /U
12、pdate the items coordinates.101. menuItem.x=vanishingPointX+menuItem.xpos3D*scaleRatio;102. menuItem.y=vanishingPointY+menuItem.ypos3D*scaleRatio;103. 104.105. /Call the function that sorts the items so they overlap each other correctly106. sortZ();107. 108.109. /This function sorts the items so the
13、y overlap each other correctly110. function sortZ():void 111.112. /Sort the array so that the item which has the highest 113. /z position (= furthest away) is first in the array114. menuItems.sortOn(zpos3D, Array.NUMERIC | Array.DESCENDING);115.116. /Set new child indexes for the images117. for (var
14、 i:uint = 0; i NUMBER_OF_ITEMS; i+) 118. setChildIndex(menuItemsi, i);119. 120. 121.122. /This function is called when a mouse is over an item123. function mouseOverItem(e:Event):void 124.125. /Change the alpha to 1126. e.target.alpha=1;127. 128.129. /This function is called when a mouse is out of an item130. function mouseOutItem(e:Event):void 131.132. /
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 长春光华学院《传播学教程》2025-2026学年期末试卷
- 东城品牌认证评价通则编制说明
- 长春中医药大学《不动产估价》2025-2026学年期末试卷
- 2024河南省建筑安全员知识题库附答案
- 2024河南省建筑安全员C证(专职安全员)考试题库
- 四边形及多边形课件2025-2026学年人教版八年级数学下册
- 2024年共建共享和美乡村作文500字
- 如何制作油漆施工方案(3篇)
- 小型农场营销方案(3篇)
- 惊喜式营销方案(3篇)
- 建筑工程安全建筑工程安全专项施工方案编制指南
- 《中考英语阅读理解》
- 首届不动产登记技能大赛试题库-2不动产登记代理实务
- 江苏省南京市2024年高二上学期期中考试英语试题含解析
- 2024物业管理条例课件
- DB32T3916-2020建筑地基基础检测规程
- 区域分析与规划课件
- 中深层地热供热技术规范 井下换热
- 隔膜泵国内十大制造商排行
- (完整版)一年级数独100题
- 福建省危险废物处置设施运行企业名单
评论
0/150
提交评论