• 菜单


    点击目标对象时菜单出来,点击其他地方时菜单消失,这个问题之前想了好多办法都没解决,后来发现时要在全局有个click事件,在这个全局click事件中进行处理就OK

    那么看一下我的程序吧

    Xml代码
    1. <spanstyle="font-size: large;"><?xmlversion="1.0"encoding="utf-8"?> 
    2. <s:Applicationxmlns:fx="http://ns.adobe.com/mxml/2009"  
    3.                xmlns:s="library://ns.adobe.com/flex/spark"  
    4.                xmlns:mx="library://ns.adobe.com/flex/mx"minWidth="955"minHeight="600" 
    5.                creationComplete="init()" 
    6.                click="application1_clickHandler(event)"xmlns:components="components.*"> 
    7.     <s:layout> 
    8.         <s:BasicLayout/> 
    9.     </s:layout> 
    10.     <fx:Script> 
    11.         <![CDATA[
    12.             import mx.collections.ArrayList;
    13.             var list:mx.controls.List=new mx.controls.List();
    14.             protected function init():void{
    15.                 var arr:ArrayList=new ArrayList();
    16.                 arr.addItem("百度");
    17.                 arr.addItem("有道");
    18.                 arr.addItem("必应");
    19.                
    20.                 list.dataProvider=arr;
    21.                 list.x=408;
    22.                 list.y=46;
    23.                 list.width=40;
    24.                 list.height=90;
    25.                 list.id="cityList";
    26.                
    27.                 this.addElement(list);
    28.                 list.setVisible(false);
    29.                
    30.                
    31.                 list.addEventListener(MouseEvent.CLICK,listClick);
    32.                
    33.             }
    34.            
    35.             protected function listClick(event:MouseEvent):void{
    36.                 mylabel.text=list.selectedItem.valueOf();
    37.                 list.visible=false;
    38.                 var u:URLRequest;
    39.                 if(mylabel.text=="百度"){
    40.                     u=new URLRequest("http://www.baidu.com");
    41.                 }else if(mylabel.text=="有道"){
    42.                     u=new URLRequest("http://www.youdao.com");
    43.                 }else if(mylabel.text=="必应"){
    44.                     u=new URLRequest("http://www.bing.com");
    45.                 }
    46.                 navigateToURL(u);//跳到新窗口
    47.             }
    48.            
    49.            
    50.            
    51.             //注意这里,就是在这里进行事件判断处理
    52.             protected function application1_clickHandler(event:MouseEvent):void
    53.             {
    54.                 if(event.target.id=="linkBtnImg"){
    55.                     list.visible=true;
    56.                 }else{
    57.                     list.visible=false;
    58.                 }
    59.             }
    60.            
    61.            
    62.    
    63.         ]]> 
    64.     </fx:Script> 
    65.      
    66.      
    67.     <s:Labelid="mylabel"  x="285"y="183"/> 
    68.     <mx:LinkButtonid="linkBtnImg"  x="285"y="40"icon="@Embed('img/11111.png')"width="116"/> 
    69.  
    70.  
    71. </s:Application> 
    72. </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>
    

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

    效果如下

     

  • 相关阅读:
    Websphere 系列的https证书的配置说明
    Linux下运行windows程序
    Linux常见命令(三)
    使用Java语言开发微信公众平台(八)——自定义菜单功能
    Linux常见命令(二)
    微信小程序,前端大梦想(八)
    微信小程序,前端大梦想(七)
    使用Java语言开发微信公众平台(七)——音乐消息的回复
    微信小程序,前端大梦想(六)
    微信小程序,前端大梦想(五)
  • 原文地址:https://www.cnblogs.com/regalys168/p/3626861.html
Copyright © 2020-2023  润新知