Fork me on GitHub Fork me on Gitee

flex RemoteObject 的两种使用方法

这里使用的是django1.6 和 postgreSQL9.0  FlashBuilder4.5

django方面就不说了,根据文档来做,建好模块,配置好数据库等等

 

创建 gateway 和 times_get

 

在url.py加上路径

 

 

现在来看 RemoteObject 的两种方法

第一种

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
 3                        xmlns:s="library://ns.adobe.com/flex/spark" 
 4                        xmlns:mx="library://ns.adobe.com/flex/mx"
 5                        creationComplete="init()">
 6     <fx:Declarations>
 7         <!-- Place non-visual elements (e.g., services, value objects) here -->
 8     </fx:Declarations>
 9     <fx:Script>
10         <![CDATA[
11             import mx.rpc.AbstractOperation;
12             import mx.rpc.events.FaultEvent;
13             import mx.rpc.events.ResultEvent;
14             import mx.rpc.remoting.mxml.RemoteObject;
15             import mx.formatters.DateFormatter;
16             
17             private function init():void{
18                 var ro:RemoteObject = new RemoteObject();
19                 ro.destination = "times_get";
20                 ro.endpoint = "http://127.0.0.1:8000/gateway/";
21                 var operation:AbstractOperation = ro.getOperation("get");
22                 ro.addEventListener(ResultEvent.RESULT, resultHandler);
23                 ro.addEventListener(FaultEvent.FAULT, faultHandler);
24                 operation.send();
25                 
26                 function resultHandler(event:ResultEvent):void{
27                     trace(event.result);
28                     dg.dataProvider = event.result;
29                 }
30                 
31                 function faultHandler(event:FaultEvent):void{
32                     trace(event.fault);
33                 }
34             }
35             
36             private function data_function(self:Object, column:DataGridColumn):String{
37                 var df:DateFormatter = new DateFormatter();
38                 //df.formatString = "YYYY-MM-DD JJ:NN:SS";
39                 df.formatString = "YYYY-MM-DD";
40                 return df.format(self.times);
41             }
42         ]]>
43     </fx:Script>
44     
45     <mx:DataGrid id="dg" width="100%" height="100%">
46         <mx:columns>
47             <mx:DataGridColumn dataField="times" headerText="时间" labelFunction="data_function"/>
48         </mx:columns>
49     </mx:DataGrid>
50         
51 </s:WindowedApplication>

 如果要使用其他方法 只要把

ro.getOperation("get");的get换成你想要的方法名就行。
operation.send();把想传送的数据放到括号里就行。

第二种

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
 3                        xmlns:s="library://ns.adobe.com/flex/spark" 
 4                        xmlns:mx="library://ns.adobe.com/flex/mx"
 5                        creationComplete="init()"
 6                        >
 7     <fx:Declarations>
 8         <!-- Place non-visual elements (e.g., services, value objects) here -->
 9         <s:ChannelSet id="channels">
10             <s:AMFChannel id="pyamf" uri="http://127.0.0.1:8000/gateway/"/>
11         </s:ChannelSet>
12         
13         <s:RemoteObject id="ro"
14                         channelSet="{channels}" 
15                         destination="times_get"
16                         showBusyCursor="true"
17                         >
18             
19             <s:method name="get" 
20                       result="Success(event)"
21                       fault="onFault(event)"/> 
22             
23         </s:RemoteObject>
24     </fx:Declarations>
25     <fx:Script>
26         <![CDATA[
27             import mx.rpc.events.FaultEvent;
28             import mx.rpc.events.ResultEvent;
29             import mx.formatters.DateFormatter;
30             
31             private function init():void{
32                 ro.get();
33             }
34             
35             private function Success(event:ResultEvent):void{
36                 trace(event.result);
37                 dg.dataProvider = event.result;        
38             }
39             
40             private function onFault(event:FaultEvent):void{
41                 trace(event.fault);
42             }
43             
44             private function data_function(self:Object, column:DataGridColumn):String{
45                 var df:DateFormatter = new DateFormatter();
46                 //df.formatString = "YYYY-MM-DD JJ:NN:SS";
47                 df.formatString = "YYYY-MM-DD";
48                 return df.format(self.times);
49             }
50         ]]>
51     </fx:Script>
52     <mx:DataGrid id="dg" width="100%" height="100%">
53         <mx:columns>
54             <mx:DataGridColumn dataField="times" headerText="时间" labelFunction="data_function"/>
55         </mx:columns>
56     </mx:DataGrid>
57 </s:WindowedApplication>

 

结果:

posted @ 2013-11-19 10:22  伴途の永远  阅读(864)  评论(0编辑  收藏  举报