httpservice 公共类

flex httpservice 公共类

一、

ContractedBlock.gif ExpandedBlockStart.gif 代码
 
    
package
{
import flash.events.
* ;
import mx.collections.ArrayCollection;
import mx.collections.IViewCursor;
import mx.core.Application;
import mx.rpc.events.ResultEvent;
import mx.rpc.http.HTTPService;
import mx.utils.ArrayUtil;
public class PhotoService
{
private
var service:HTTPService;
[Bindable]
public
var galleries:ArrayCollection;
public
function PhotoService(url:String)
{
service
= new HTTPService();
service.url
= url;
service.addEventListener(ResultEvent.RESULT, resultHandler);
service.send();
}
private
function resultHandler(event:ResultEvent): void
{
var result:ArrayCollection = event.result.galleries.gallery is ArrayCollection
? event.result.galleries.gallery as ArrayCollection
:
new ArrayCollection(ArrayUtil.toArray(event.result.galleries.gallery));
var temp:ArrayCollection = new ArrayCollection();
var cursor:IViewCursor = result.createCursor();
while ( ! cursor.afterLast)
{
temp.addItem(
new Gallery(cursor.current)); // 解析成自己想要的类
cursor.moveNext();
}
galleries
= temp;
}
}
}

 

二、

 

ContractedBlock.gif ExpandedBlockStart.gif 代码
 
    
// 封装类MyServiceCall
package myas
{
import mx.rpc.events.ResultEvent;
import mx.rpc.http.HTTPService;
public class MyServiceCall
{
private
var hs:HTTPService;
private
var f:Function;
public
function MyServiceCall()
{
hs
= new HTTPService;
hs.url
= " data/ex.xml " ;
hs.addEventListener(ResultEvent.RESULT, resultHandler);
}
public
function doCall(param:Function): void
{
this .f = param;
hs.send();
}
public
function resultHandler(event:ResultEvent): void
{
f.call(
null , event);
}
}
}
// main
xml version = " 1.0 " encoding = " utf-8 " ?>
< mx:Application xmlns:mx = " http://www.adobe.com/2006/mxml "
layout
= " absolute "
creationComplete
= " init() " >
< mx:Script >

< / mx:Script>
< / mx:Application>

 

 

 

 

你可能感兴趣的:(httpservice 公共类)