`
txf2004
  • 浏览: 7206719 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

【教程】垂直的3D滚轮菜单

阅读更多

继我上次静心翻译国外友人的完美作品已经是大概两三年了,这此终于有空闲的时间来翻译一把这些完美的教程,也算把这个博客继续写下去。

我目前的想法是打算将这个博客就定位于RIA 平台及WEB设计技术,主要是转载,评论一些技术文章,同时也会翻译我觉得很优秀的文章

垂直的3D滚轮看起来好像很复杂,不过借助FLASH的3D新特性,在不需要导入额外包的情况下就可以轻松实现了

创建垂直的3d滚轮菜单

在这篇教程中,您可以学到如何创建一个3d的垂直滚轮菜单,滚轮的旋转速度将由鼠标的滚动速度决定

In this tutorial I will show you how to create a vertical 3D carousel with the help of ActionScript 3! We will determine the rotation speed according to mouse movement.

flashplayer effect 请查看原文链接 http://tutorials.flashmymind.com/2009/03/vertical-3d-carousel-with-actionscript-3/

(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player .)

Setting up the environment 环境设置

1. Create a new Flash document of size 550×400. 创建一个550×400的flash文档

2. Draw a rectangle with rounded corners. I made the rectangle 158×35 pixels. I used a white stroke and for the fill #0F7E88.绘制一个158×35的圆角矩形,使用#OF7E88颜色和白色的宽笔触填充这个矩形

Flash Menu Item Rectangle

3. Convert the rectangle to a movie clip named “Menu Item”. Set the registration point to the center .将这个矩形转换为名为Menu Item的MC,并将注册点设置为矩形中心

4. Inside the Menu Item movie clip, create a dynamic text field. Make it wide enough and type some text in it.在矩形的内部创建适当大小的文本框

Flash Menu Item with Dynamic Text field.

5. Give the text field an instance name of “menuItemText “. 将该文本命名为menuItemText

6. Embed the following fonts. 在FLASH中内嵌以下字体

Flash Embed Fonts

7. No go back to the main timeline and remove the Menu Item movie clip from the stage.转到主舞台的时间轴的第一帧,并删除掉舞台上的东西

8. Linkage the Menu Item movie clip to a class named “MenuItem”. 将MC链接到名为MenuItem的AS类

Moving to ActionScript 3 转到AS3下面来工作

9. In the first frame of your Flash movie type the following. 为该AS文件添加以下内容

//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[ i] ) ;

//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] , 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. You are done, test your movie! I hope you enjoyed this ActionScript 3 tutorial …

好收工

Download .fla

分享到:
评论

相关推荐

    33款JQuery或JS动画效果的导航菜单

    5. 鼠标滚轮触发:利用鼠标滚轮触发菜单的动画,如滚动下拉、放大缩小等。 6. 3D效果:通过CSS3和JavaScript实现的立体旋转、翻转等效果,增加视觉冲击力。 7. 时间轴样式:将菜单项按照时间顺序排列,呈现动态的...

    summer 09 3D高级功能应用.pdf

    单纯使用鼠标滚轮则实现垂直方向上的移动。此外,通过按【Shift+S】键可以实现3D模式下PCB板的单层显示,便于更细致地观察和编辑特定层面的细节。 综上所述,Altium Designer Summer 09的3D高级功能应用极大提升了...

    Android-PickerView-master.zip_android

    在Android开发中,PickerView是一个常用的组件,常用于实现类似于iOS中的3D滚轮效果。这个"Android-PickerView-master.zip"文件很可能包含了实现这一特性的完整源代码和资源文件,让我们来深入了解一下这个组件及其...

    ubuntu10.10特效设置教程

    Ubuntu 10.10 特效设置教程主要涉及的是如何通过 CompizConfig 设置管理器来增强桌面体验,包括3D桌面、窗口管理、透明效果和动画等方面。以下是详细的知识点说明: 1. **安装 CompizConfig 设置管理器**: 使用 `...

    UG7.5入门建模教程.doc

    这个入门建模教程主要介绍了如何使用UG7.5进行基础的3D建模操作,包括界面熟悉、工具栏定制以及草图绘制等关键步骤。 首先,创建新模型文件时,用户需要在弹出的对话框中选择“模型”类型,输入英文或数字组成的...

    JQuery&CSS;&CSS;+DIV实例大全.rar

    通用性强的jquery带箭头跟随的垂直菜单组(jquery vmenu)插件下载 48.推荐jQuery黑色多级横向菜单导航(带动画效果) 49.学习jQuery简单伸缩菜单代码实例 50.一款jquery仿flash滑动左侧菜单插件代码下载 51.一...

    blender quick start

    子类别可通过滚动面板访问,Shift+鼠标滚轮可滚动面板,Ctrl+鼠标滚轮可缩放面板,右键拖放可组织面板布局,实现垂直对齐。 ### 对象操作与编辑 #### 默认场景: Blender默认场景包含一个立方体、一盏灯和一个相机...

    Blender Hot key

    23. **连接两个垂直元素**: `J` 用于连接两个垂直的边。 24. **合并所有选中物体**: `Ctrl + J` 把所有选中的物体合并成一个。 25. **三角化面**: `Ctrl + T` 将面转换为三角形网格,这对渲染和某些运算很有帮助。...

    windows快捷键

    - **Shift+Win+↑上方向键**: 垂直最大化当前活动窗口,但水平宽度保持不变。 - **Win+↓下方向键**: 最小化当前活动窗口或恢复先前最大化的窗口。 - **Win+左/右方向键**: 将窗口靠边到屏幕的左侧或右侧,与将窗口...

    win7 快捷键

    - `Shift + Win + ↑`:垂直最大化当前窗口,保持水平宽度不变。 - `Win + ↓`:最小化当前窗口或恢复先前被最大化的窗口。 - `Win + 左/右方向键`:将窗口拉伸至屏幕左侧或右侧。 - `Shift + Win + 左/右方向键...

    最新win7快捷键大全

    - `Shift + Win + ↑`:垂直最大化当前窗口,保持水平宽度不变。 - `Win + ↓`:最小化当前窗口或恢复先前的最大化窗口。 - `Win + 左/右方向键`:将窗口拖至屏幕左侧或右侧。 - `Shift + Win + 左/右方向键`:...

    win7快捷键汇总

    - `Shift + Win + ↑`:垂直最大化窗口,保持宽度不变。 - `Win + ↓`:最小化当前窗口或恢复之前被最大化的窗口。 - `Win + 左/右方向键`:将窗口向屏幕左侧或右侧靠拢,适应半屏模式。 - `Shift + Win + 左/右...

    Windows7快捷键集锦.pdf

    - `Shift + Win + ↑`:使窗口垂直最大化,保持水平宽度不变。 - `Win + ↓`:最小化窗口,或者恢复先前的最大化窗口。 - `Win + 左/右方向键`:将窗口拖动到屏幕的左右两侧。 - `Shift + Win + 左/右方向键`:...

    win7快捷键

    26. **Win + Tab**:启用Flip3D,以3D效果在窗口之间切换。 27. **Alt+Tab**:在所有打开的窗口间切换。 28. **基础快捷键**:包括F1帮助、Ctrl+C复制、Ctrl+X剪切、Ctrl+V粘贴、Ctrl+Z撤销、Ctrl+Y重做、Delete...

    windows7键盘快捷键大全

    - **Shift+Win+↑**:垂直最大化当前窗口,保持其水平宽度不变。 - **Win+↓**:最小化当前窗口或恢复先前最大化状态。 - **Win+左/右方向键**:将当前窗口移至屏幕左侧或右侧。 - **Shift+Win+左/右方向键**:将...

    window7快捷键.pdf

    - `Shift + Win + ↑`:垂直最大化当前窗口,保持宽度不变。 - `Win + ↓`:最小化窗口或恢复先前的最大化窗口。 - `Win + 左/右方向键`:将窗口拉至屏幕左侧或右侧。 - `Shift + Win + 左/右方向键`:将窗口...

    win7键盘快捷键

    - **Shift+Win+↑上方向键**:垂直最大化当前窗口,即窗口的高度被最大化但宽度保持不变。 - **Win+↓下方向键**:最小化当前窗口或恢复之前最大化的窗口。 - **Win+左/右方向键**:使当前窗口靠向屏幕的左侧或右侧...

    3DCloudPoint.rar

    MFC是微软提供的一种C++类库,用于构建Windows应用程序,而OpenGL则是一个强大的图形处理API,用于生成2D和3D图像。 首先,我们需要了解MFC的基本框架。MFC应用通常由一系列类组成,如CWinApp、CWnd、CDialog等,...

    Windows7键盘快捷键大全.pdf

    26. **Win + Tab**:启用Flip3D任务切换,以3D视图展示窗口。 基础快捷键包括: - **F1**:显示帮助信息。 - **Ctrl+C** 和 **Ctrl+Insert**:复制选中的内容。 - **Ctrl+X**:剪切选中的内容。 - **Ctrl+V** 和 *...

    F14使用说明

    这部分操作在手册中虽未详细展开,但提供了明确的指引:用户可以通过MWorks的“试验-&gt;模型优化”菜单进入模型优化界面,而在实际操作之前,用户应当通过查阅《MWorks 试验设计工具-模型优化》第5.2节和《MWorks 用户...

Global site tag (gtag.js) - Google Analytics