zoukankan      html  css  js  c++  java
  • Flex远程访问获取数据--HTTPService

    编写service类:

    package services {
        import com.adobe.serialization.json.JSON;
        
        import log.LogUtil;
        
        import mx.collections.ArrayCollection;
        import mx.collections.XMLListCollection;
        import mx.controls.Alert;
        import mx.rpc.events.ResultEvent;
        import mx.rpc.http.mxml.HTTPService;
        
        
        public class CategoryService extends HTTPService {
            [Bindable]
            public var categoryArray:ArrayCollection;
            public var testFlag:Boolean = true;
            
            public function CategoryService(rootURL:String=null, destination:String=null) {
                super(rootURL, destination);
                this.url = "http://192.168.1.210:8081/xxx.action";
    //url为远程请求接口
                addEventListener(ResultEvent.RESULT, handleCategoryResult);
                
            }
            
            private function handleCategoryResult(event:ResultEvent):void{
                var rawData:String =  String(event.result);
                trace(rawData);
                LogUtil.debug("CategoryService",rawData);
                var o:Object = com.adobe.serialization.json.JSON.decode(rawData);//对结果进行json转换  
                categoryArray = new ArrayCollection(o.result);
            }    
            
                    
            
        }
    }

    结果集接收之后进行json格式转换,需要导入as3corelib.swc
    在XML中引入:

      

    <fx:Declarations>
            <!-- 将非可视元素(例如服务、值对象)放在此处 -->
            <services:CategoryService id="categoryService"/>
        </fx:Declarations>

    在方法中调用:

    <?xml version="1.0" encoding="utf-8"?>
    <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" 
                 xmlns:s="library://ns.adobe.com/flex/spark" 
                 xmlns:mx="library://ns.adobe.com/flex/mx" width="342" height="60" xmlns:services="services.*" initialize="group1_initializeHandler(event)">
        <fx:Declarations>
            <!-- 将非可视元素(例如服务、值对象)放在此处 -->
            <services:CategoryService id="categoryService"/>
        </fx:Declarations>
        
        <fx:Script>
            <![CDATA[
                import mx.collections.ArrayCollection;
                import mx.events.FlexEvent;
                
                import spark.events.IndexChangeEvent;
                
                            
                  
                protected function group1_initializeHandler(event:FlexEvent):void
                {
                    if(categoryService.testFlag){
                        categoryService.localTest();
                    }else{
                        categoryService.send();
                    }
                    
                    
                }
                
            ]]>
        </fx:Script>
        
           <s:DropDownList id="categoryList" x="92" y="29" width="174"
                    dataProvider="{categoryService.categoryArray}"
                    labelField="name"
                    prompt="请选择"
                    change="updateSelection(event);"
                    />
        
    
        
    </s:Group>
  • 相关阅读:
    QTableWidget的使用和美工总结
    pyqt下QTableWidget使用方法小结(转)
    改变QTableWidget 行高(转)
    Qt中 文件对话框QFileDialog 的使用
    Qt:拖拽图片到QLabel上并显示(转)
    Qt获取组合键(转)
    Qt图片显示效率的比较(转)
    QComboBox用法小列(转)
    TinyXML:一个优秀的C++ XML解析器(转)
    JZOJ 3099. Vigenère密码 NOIP2012
  • 原文地址:https://www.cnblogs.com/sagech/p/5630986.html
Copyright © 2011-2022 走看看