当前位置:首页 > 开发 > 移动开发 > 正文

flex 如何用HTTPService 与后台交互数据

发表于: 2008-11-28   作者:coral0212   来源:转载   浏览:
摘要: <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundGradientAlphas="[0.72
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundGradientAlphas="[0.72, 1.0]" backgroundGradientColors="[#FFFFFF, #FFFFFF]">
	
	<mx:HTTPService 
  		showBusyCursor="true"  
  		id="loginSrv" 
  		result="doResult();"  
  	    method="GET"
  		url="http://localhost:8080/UserManager/checkUser.do"> 
 		<mx:request> 
 			<userName>  
 				{txtname.text} 
 			</userName> 
 			<password> 
				{txtpwd.text}
 			</password> 
 		</mx:request> 
	</mx:HTTPService> 
	<mx:HTTPService 
  		showBusyCursor="true"  
  		id="loadUsers"  
  	    method="GET" result="users = event.result.users.user"
  		url="http://localhost:8080/UserManager/loadAllUsers.do">  
	</mx:HTTPService> 
		<mx:Script>
		<![CDATA[
		    import mx.controls.Alert;
            import mx.utils.ObjectUtil;
            import mx.collections.ArrayCollection; 
            
            [Bindable]
            var users:ArrayCollection=new ArrayCollection();
			internal function doResult():void
			{ 
				var returnValue:String=loginSrv.lastResult.result.msg; 
       			if(returnValue=="sucess") 
  				{   
  					login.visible=false;  
  					loadUsers.send();
  					userList.visible=true;  					
        		}  
 				else 
   				{  
					Alert.show("登录失败","提示信息",Alert.OK,this,null,null,Alert.YES); 
              	}
			} 
		    private function index_sortCompareFunc(itemA:Object, itemB:Object):int {
                // Make sure itemA has an "index" property.
                if (!itemA.hasOwnProperty("id")) {
                    itemA.index = null;
                }
                // Make sure itemB has an "index" property.
                if (!itemB.hasOwnProperty("id")) {
                    itemB.index = null;
                }
                // Perform a numeric sort.
                return ObjectUtil.numericCompare(itemA.index, itemB.index);
            } 
		]]>
	</mx:Script>
	<mx:Panel id="login" x="285.5" y="127" width="341" height="238" layout="absolute" fontFamily="Arial" fontSize="13" color="#3C280B" borderStyle="none" borderColor="#CC0B0B" cornerRadius="10" alpha="0.64">
		<mx:TextInput id="txtname" x="101" y="34" width="172" displayAsPassword="true" editable="true" enabled="true"/>
		<mx:Button x="92" y="130" label="登录" labelPlacement="top" enabled="true" click="loginSrv.send();"/>
		<mx:Button x="183" y="130" label="取消"/>
		<mx:TextInput id="txtpwd" x="101" y="75" width="172" displayAsPassword="true" editable="true" enabled="true"/>
		<mx:Label x="44" y="36" text="帐号:" width="49" height="20" enabled="true"/>
		<mx:Label x="44" y="77" text="密码:" width="49" height="20" enabled="true"/>
	</mx:Panel>
	<mx:Panel id="userList" x="181.5" y="98" width="576" height="311" layout="absolute" visible="false">
		<mx:DataGrid x="0" y="0" width="556" height="271" sortableColumns="true" dataProvider="{users}" editable="true" enabled="true">
			<mx:columns>
			    <mx:DataGridColumn headerText="编号" dataField="id"  />
				<mx:DataGridColumn headerText="姓名" dataField="userName" />
				<mx:DataGridColumn headerText="密码" dataField="password"/>
				<mx:DataGridColumn headerText="邮件" dataField="email"/>
				<mx:DataGridColumn headerText="地址" dataField="address"/>
			</mx:columns>
		</mx:DataGrid>
	</mx:Panel>
</mx:Application>
 

flex 如何用HTTPService 与后台交互数据

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号