Flex4之简单菜单制作

首先呢说明一下,我写的这个菜单呢,为了符合我的项目需要没有用到任何menu组件,用到时list组件进行构造,中间有一个比较重要:就是点击目标对象时菜单出来,点击其他地方时菜单消失,这个问题之前想了好多办法都没解决,后来发现时要在全局有个click事件,在这个全局click事件中进行处理就OK

那么看一下我的程序吧

 

<?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>

 点击菜单上每一项都可以跳到新网址上去

 效果如下

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值