• 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>
  • 相关阅读:
    springboot初始篇(一)
    SpringBoot使用数据库JdbcTemplate(三)
    java实现分页查询
    设计模式之单例模式
    ❤️考研数学公式❤️
    ❤️图的遍历❤️
    图的存储
    图的基本概念
    森林与二叉树的应用
    树相关的代码题
  • 原文地址:https://www.cnblogs.com/daichangya/p/1706131.html
Copyright © 2020-2023  润新知