New API HTTPMultiService and HTTPOperation in Flex 3.4

来源:互联网 发布:ubuntu删除目录命令 编辑:程序博客网 时间:2024/05/22 18:10

New API HTTPMultiService and HTTPOperation in Flex 3.4

<!-- HTTPMultiServiceSample,摘自(http://shigeru-nakagaki.com/index.cfm/2009/8/27/20090827-HTTPMultiService-and-HTTPOperation-in-Flex340)-->
<?xml version="1.0" encoding="utf-8"?><mx:Application layout="vertical"     xmlns:mx="http://www.adobe.com/2006/mxml"     minWidth="1024" minHeight="768"     viewSourceURL="srcview/index.html"     creationComplete="onCreationComplete()">        <mx:Script>        <![CDATA[            //import com.adobe.serialization.json.JSONDecoder;            import mx.rpc.AsyncToken;            import mx.utils.ObjectUtil;            import mx.controls.Alert;            import mx.rpc.events.FaultEvent;            import mx.rpc.events.ResultEvent;                                    private function onCreationComplete():void            {                var s:String = application.url;                trace(s);                var index:int = s.indexOf(".swf");                s = s.substr(0,index);                trace(s);                index = s.lastIndexOf("/");                s = s.substr(0,index);                trace(s);                                srv.baseURL = s + "/";                                // if you set a service at constructor, you can&apos;t set srv.operationList = [op];                // also you can&apos;t get operation if you set a service at constructor                 //var op:mx.rpc.http.Operation = new mx.rpc.http.Operation(srv, "getData");                var op:mx.rpc.http.Operation = new mx.rpc.http.Operation(null, "getData");                op.url = s + "/test.cfm";                op.method = URLRequestMethod.POST;                op.addEventListener(ResultEvent.RESULT, onResult);                op.addEventListener(FaultEvent.FAULT, onFault);                                srv.operationList = [op];            }                                    private function test():void            {                var args:Object = new Object();                args.hoge = "abc";                args.foo = 123;                                var op:mx.rpc.http.Operation = mx.rpc.http.Operation(srv.getOperation("getData"));                trace("result event : " + op.hasEventListener(ResultEvent.RESULT));                trace("fault event : " + op.hasEventListener(FaultEvent.FAULT));                                var at:AsyncToken = op.send(args);                at.bar = "XYZ";            }                        private function onResult(e:ResultEvent):void            {                /*                var json:JSONDecoder = new JSONDecoder(e.result.toString());                var obj:Object = json.getValue();                Alert.show(ObjectUtil.toString(obj),"Success");                */                Alert.show(e.result.toString(),"Success");            }                        private function onFault(e:FaultEvent):void            {                Alert.show(ObjectUtil.toString(e.fault),"Error");            }                    ]]>    </mx:Script>        <mx:HTTPMultiService id="srv" />        <mx:Button label="test" click="test()"/>    </mx:Application>
原创粉丝点击