Flex4之简单菜单制作
2012-02-25 08:56
363 查看
首先呢说明一下,我写的这个菜单呢,为了符合我的项目需要没有用到任何menu组件,用到时list组件进行构造,中间有一个比较重要:就是点击目标对象时菜单出来,点击其他地方时菜单消失,这个问题之前想了好多办法都没解决,后来发现时要在全局有个click事件,在这个全局click事件中进行处理就OK
那么看一下我的程序吧
Xml代码
![](http://javacrazyer.iteye.com/images/icon_copy.gif)
![](http://javacrazyer.iteye.com/images/icon_star.png)
![](http://javacrazyer.iteye.com/images/spinner.gif)
<SPAN style="FONT-SIZE: large"><?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
creationComplete="init()"
click="application1_clickHandler(event)" xmlns:components="components.*">
<s:layout>
<s:BasicLayout/>
</s:layout>
<fx:Script>
<![CDATA[
import mx.collections.ArrayList;
var list:mx.controls.List=new mx.controls.List();
protected function init():void{
var arr:ArrayList=new ArrayList();
arr.addItem("百度");
arr.addItem("有道");
arr.addItem("必应");
list.dataProvider=arr;
list.x=408;
list.y=46;
list.width=40;
list.height=90;
list.id="cityList";
this.addElement(list);
list.setVisible(false);
list.addEventListener(MouseEvent.CLICK,listClick);
}
protected function listClick(event:MouseEvent):void{
mylabel.text=list.selectedItem.valueOf();
list.visible=false;
var u:URLRequest;
if(mylabel.text=="百度"){
u=new URLRequest("http://www.baidu.com");
}else if(mylabel.text=="有道"){
u=new URLRequest("http://www.youdao.com");
}else if(mylabel.text=="必应"){
u=new URLRequest("http://www.bing.com");
}
navigateToURL(u);//跳到新窗口
}
//注意这里,就是在这里进行事件判断处理
protected function application1_clickHandler(event:MouseEvent):void
{
if(event.target.id=="linkBtnImg"){
list.visible=true;
}else{
list.visible=false;
}
}
]]>
</fx:Script>
<s:Label id="mylabel" x="285" y="183"/>
<mx:LinkButton id="linkBtnImg" x="285" y="40" icon="@Embed('img/11111.png')" width="116"/>
</s:Application>
</SPAN>
点击菜单上每一项都可以跳到新网址上去
那么看一下我的程序吧
Xml代码
![](http://javacrazyer.iteye.com/images/icon_copy.gif)
![](http://javacrazyer.iteye.com/images/icon_star.png)
![](http://javacrazyer.iteye.com/images/spinner.gif)
<SPAN style="FONT-SIZE: large"><?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
creationComplete="init()"
click="application1_clickHandler(event)" xmlns:components="components.*">
<s:layout>
<s:BasicLayout/>
</s:layout>
<fx:Script>
<![CDATA[
import mx.collections.ArrayList;
var list:mx.controls.List=new mx.controls.List();
protected function init():void{
var arr:ArrayList=new ArrayList();
arr.addItem("百度");
arr.addItem("有道");
arr.addItem("必应");
list.dataProvider=arr;
list.x=408;
list.y=46;
list.width=40;
list.height=90;
list.id="cityList";
this.addElement(list);
list.setVisible(false);
list.addEventListener(MouseEvent.CLICK,listClick);
}
protected function listClick(event:MouseEvent):void{
mylabel.text=list.selectedItem.valueOf();
list.visible=false;
var u:URLRequest;
if(mylabel.text=="百度"){
u=new URLRequest("http://www.baidu.com");
}else if(mylabel.text=="有道"){
u=new URLRequest("http://www.youdao.com");
}else if(mylabel.text=="必应"){
u=new URLRequest("http://www.bing.com");
}
navigateToURL(u);//跳到新窗口
}
//注意这里,就是在这里进行事件判断处理
protected function application1_clickHandler(event:MouseEvent):void
{
if(event.target.id=="linkBtnImg"){
list.visible=true;
}else{
list.visible=false;
}
}
]]>
</fx:Script>
<s:Label id="mylabel" x="285" y="183"/>
<mx:LinkButton id="linkBtnImg" x="285" y="40" icon="@Embed('img/11111.png')" width="116"/>
</s:Application>
</SPAN>
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="init()" click="application1_clickHandler(event)" xmlns:components="components.*"> <s:layout> <s:BasicLayout/> </s:layout> <fx:Script> <![CDATA[ import mx.collections.ArrayList; var list:mx.controls.List=new mx.controls.List(); protected function init():void{ var arr:ArrayList=new ArrayList(); arr.addItem("百度"); arr.addItem("有道"); arr.addItem("必应"); list.dataProvider=arr; list.x=408; list.y=46; list.width=40; list.height=90; list.id="cityList"; this.addElement(list); list.setVisible(false); list.addEventListener(MouseEvent.CLICK,listClick); } protected function listClick(event:MouseEvent):void{ mylabel.text=list.selectedItem.valueOf(); list.visible=false; var u:URLRequest; if(mylabel.text=="百度"){ u=new URLRequest("http://www.baidu.com"); }else if(mylabel.text=="有道"){ u=new URLRequest("http://www.youdao.com"); }else if(mylabel.text=="必应"){ u=new URLRequest("http://www.bing.com"); } navigateToURL(u);//跳到新窗口 } //注意这里,就是在这里进行事件判断处理 protected function application1_clickHandler(event:MouseEvent):void { if(event.target.id=="linkBtnImg"){ list.visible=true; }else{ list.visible=false; } } ]]> </fx:Script> <s:Label id="mylabel" x="285" y="183"/> <mx:LinkButton id="linkBtnImg" x="285" y="40" icon="@Embed('img/11111.png')" width="116"/> </s:Application>
点击菜单上每一项都可以跳到新网址上去
相关文章推荐
- 天易15----jquery实现简单的后台左侧菜单制作
- 使用Unity制作GTA武器菜单的简单思路
- CSS3简单动画效果与使用列表制作菜单
- JavaScript制作简单的三级联动菜单实例代码
- 用克隆来制作关联菜单,主要编辑简单.
- 用flex制作最简单的mp3播放器
- JQUERY简单的树形菜单制作
- 用flex制作简单的mp3播放器
- Ubuntu下使用dialog制作菜单执行简单脚本
- js制作简单的tab菜单切换
- J2ME中使用Canvas制作简单的游戏菜单
- Silverlight制作一个简单的菜单1-用到的知识讲解 xml数据读取,事件如何传递参数
- 如何制作安卓项目gif效果图及其简单菜单munu的计算问题
- Android开发——Fragment简单示例(二)制作一个应用菜单导航栏
- 简单的伸缩菜单-实例教学-Flash-网页制作
- Feature开发一(制作一个简单的自定义菜单)
- DIV+CSS制作二级横向弹出菜单,略简单
- 简单 纯css 多级导航菜单 制作教程1 - 使用ul li 制作导航栏
- Flex 利用Image制作动态菜单
- 用Canvas制作一个简单的操作菜单