Flex4之HTTPService获取和检索数据

http://www.adobe.com/devnet/flex/tourdeflex/ [flex air桌面版下载以及WEB版连接,浏览FLEX代码示例、资源]

http://examples.adobe.com/flex2/inproduct/sdk/explorer/explorer.html [FLEX例子演示]

本人目前使用的是FlashBuilder4,确切的说不知道怎么下载到这个版本的,反正用着挺好的

Flex4相当对与Flex3来说还是有不小的变化,比如多了个<fx:Declarations>标签元素,要求<!-- 将非可视元素(例如服务、值对象)放在此处 -->

Flex框架使用3种组建来发送和获取数据、
 HTTPService--HTTP GET AND POST OPERATIONS
 RemoteObjet--REMOTE OBJECT CONNECTIONS USING AMF[Action Message Format]
 WebService--SOAP/WSDL OPERATIONS

今天就先说下常用的HTTPService小示例

 第一步先奉上项目结构图

 
Flex4之HTTPService获取和检索数据

第二部贴上具体代码

  students.xml

<Students>
   <Student>
         <name>lucy</name>
         <sex>male</sex>
         <age>28</age>
         <marry>yes</marry>
         <x>66</x>
         <y>42</y>
 
   </Student>
   <Student>
         <name>lily</name>
         <sex>male</sex>
         <age>33</age>
         <marry>no</marry>
          <x>600</x>
         <y>500</y>
      
   </Student>
    <Student>
         <name>tom</name>
         <sex>famale</sex>
         <age>19</age>
         <marry>no</marry>
          <x>10</x>
         <y>300</y>
   </Student>
</Students>

 

  

    HTTPService.mxml

 

<?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="myService.send()"
			    >
	<fx:Script>
		<![CDATA[
			import mx.collections.ArrayCollection;
			import mx.controls.Alert;
			import mx.rpc.events.ResultEvent;
			
			import spark.events.IndexChangeEvent;
            [Bindable]
			var ps:ArrayCollection;
			[Bindable]
			var pp:Object;
			protected function myService_resultHandler(event:ResultEvent):void
			{
				ps=event.result.Students.Student;
				var x:Number=ps.getItemAt(1,1).x;
				var y:Number=ps.getItemAt(1,1).y;
				myform.x=x;
				myform.y=y;
			}

           // 这个方法,跟上个方法都是ALT+/自动生成的,具体实现得自定义
			protected function dropdownlist1_changeHandler(event:IndexChangeEvent):void
			{
				pp=event.target.selectedItem;
				myform.x=pp.x as Number;
				myform.y=pp.y as Number;
			}

           

		]]>
	</fx:Script>
	<fx:Declarations>
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
		<s:HTTPService id="myService" result="myService_resultHandler(event)" url="data/student.xml">
			
		</s:HTTPService>  
	</fx:Declarations>
	<mx:Form id="myform" width="415" height="349">
		<mx:FormItem label="姓名">
			<s:DropDownList id="plist" dataProvider="{ps}" labelField="name" change="dropdownlist1_changeHandler(event)"> 
			</s:DropDownList>
		</mx:FormItem>
		<mx:FormItem label="性别">
			<s:TextInput text="{pp.sex}"/>
		</mx:FormItem>
		<mx:FormItem label="年龄" >
			<s:TextInput text="{pp.age}"/>
		</mx:FormItem>
		<mx:FormItem label="婚否" >
			<s:TextInput text="{pp.marry}"/>
		</mx:FormItem>
	</mx:Form>
</s:Application>

 
 效果图之一


Flex4之HTTPService获取和检索数据
 

你可能感兴趣的:(数据结构,webservice,Flex,Adobe,AIR)