• httpservice 公共类


    flex httpservice 公共类

    一、

    代码
    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;
    }
    }
    }

    二、

    代码
    //封装类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>
    <!--[CDATA[
    import mx.rpc.events.ResultEvent;
    import myas.MyServiceCall;
    import mx.controls.Alert;
    private
    var result:ResultEvent;
    private
    function init():void
    {
    var mysc:MyServiceCall = new MyServiceCall;
    //调用 相当于send
    mysc.doCall(onComplete);
    }
    //调用完后的处理方法,此方法中得到返回结果
    private function onComplete(r:ResultEvent):void
    {
    result
    = r;
    }
    ]]
    -->
    </mx:Script>
    </mx:Application>
  • 相关阅读:
    平面切圆柱面的椭圆绘制
    抛物面倾斜体积积分
    计算误差函数的积分--erf(x)
    三棱椎的体积
    Mac平台上OpenCV开发环境搭建
    仿新浪右下角视频弹窗(视频弹出广告)播放器
    python爬虫之Scrapy 使用代理配置
    ip地址定位库
    python 使用 redis expire属性设置访问时间间隔
    如何做将两张图片合二为一
  • 原文地址:https://www.cnblogs.com/daichangya/p/1706131.html
Copyright © 2020-2023  润新知