|
S. 很抱歉,這份文件裡的?S忻?詞都是台?车??^的???T用法,可能大??地?^的朋友看起來??不太???T,可否??有?r間的人修改一下,以造福更多??這有興趣的人。 Macromedia Flash Remoting for Flash MX 2004 ActionScript 2.0 網??
官方網站:??按此。
??選?? flashremoting_comp_as20-win-en.exe 下載。
萬用 ActionScript
import mx.remoting.*; import mx.rpc.*; // 伺服器回?髻Y料?r,??呼叫此函式 function myTestFunction_Result (re:ResultEvent):Void { trace("回?髻Y料:" + re.result); } // 發生??理失???r,??呼叫此函式 function myTestFunction_Fault (fault:FaultEvent):Void { trace("??題訊息:" + fault.fault.description); } // 建立一??連??到 127.0.0.1 網站根目??的 myCFCDir 資料?A中的 myCFC.cfc var myService:Service = new Service( "http://127.0.0.1/flashservices/gateway", null, "myCFCDir.myCFC", null, null); // 呼叫 myService 所指向的 CFC 中的 myTestFunctino 函式,並?魅? "123" 做?????? var myPendingCall:PendingCall = myService.myTestFunction("123"); // ??這??呼叫有回?饔嵪??r,使用一?? RelayResponder 物件來?λ?做反??,這??物件在反???r??叫用我??最前面做的 myTestFunction_Result 或 myTestFunction_Fault 函式 myPendingCall.responder = new RelayResponder(this,"myTestFunction_Result","myTestFunction_Fault"); 萬用 CFC
製作步驟
1.首先??然先確定 ColdFusion MX 6.1 ( 或 BlackStone - ColdFusion MX 7 )、Flash MX 2004 及 Flash Remoting AS2 都安裝好了,且 ColdFusion 服?沼性??绦兄小?
2.在網站根目??中做一??資料?A叫 myCFCDir,裡面開一??新?n案叫 myCFC.cfc ( 若使用 ColdFusion ?冉ǖ木W站伺服器,網站根目??是預設在 ColdFusion 資料?A下的「wwwroot」)。
3.?? myCFC.cfc 的?热莞某缮狭腥f用 CFC 的?热荨?
4.用 http://127.0.0.1/myCFCDir/myCFC.cfc 網址查看 CFC 的語法是否正確,ColdFusion ??要求你先??入密碼,這是?榱税踩?起??。
5.在 Flash MX 2004 開新?n案,在功能表選「??窗」「其他面版」「?冉ㄔ?件?臁埂窻emoting」,??多跑出一??元件?欤?裡面有???? Flash Remoting AS2 的元件,?? RemotingClasses 拖一??到?鼍吧希?再?⑺??h除,如此它就??出現在這??新?n案的元件?熘小?
6.?⑸狭腥f用 ActionScript 複製到第一??影格的?幼髅姘逯校瑏K???δ愕沫h境?⒊淌酱a做適??調整。
7.?绦性? Flash ?y??是否有 trace 出「回?饔嵪ⅲ?123123」,如果有就成功了。
8.要做?e的 Flash Remoting 就直接拿上面的萬用 ActionScript 及萬用 CFC 修改就好了。
Flash 的運作過程
首先由 Flash 來看,一開始就載入了我??需要的這些類?e,然後宣告了????函式,分?e用於??理 ColdFusion 的?骰刂担?以及在發生錯誤?r做相關的??理 ( trace 出錯誤訊息 )。
接著建立 Service 物件,稱?? myService,這是一??直接指向 CFC 的物件,在這??範例中它指向 IP ?? 127.0.0.1 的伺服器 ( 就是本?C ) 根目??下 myCFCDir 資料?A中的 myCFC.cfc 這支程式。「/flashservices/gateway」是 ColdFusion 用來??理 Flash Remoting 呼叫的路徑,?o??你的 CFC 放在這台主?C的哪裡,都不??改??。
再來?绦? myService 指向的 CFC 中的 myTestFunction 函式,並?⒒??鞯? PendingCall 物件稱?? myPendingCall,這??物件是 Flash 在送出?? CFC 的呼叫?r就立刻建立的,可以?⑺?想像成呼叫 CFC 的這???幼鳎?而非 CFC 回?鞯慕Y果。
最後我??建立一?? RelayResponder 物件,並把它指給 myPendingCall 的 responder。這是?iT用來反?? ColdFusion 回?髦档模?反??的方法就是一開頭建立的????函?担?所以在建立這??物件的同?r,?⒛?????函?得?稱丟給它了。
?? CFC 丟回資料?r, myPendingCall 就??叫用自己的 responder,並?Q定?绦谐晒???是失?〉暮?式來??理這些資料。
其他
Macromedia Flash Remoting for Flash MX 2004 ActionScript 2.0 ??包含很多其他的功能,也有其他的做法來完成 CFC 呼叫。在裝好 Flash Remoting 之後,這些在 Flash 的說明面板中都有,只是英文的讀起來比較不???T。
Macromedia Flash Remoting for Flash MX 2004 ActionScript 2.0 是我活到現在看過最長的??體名字 ( 嗯...來日方長,只要 Macromedia ??在,也許有?C??看到更長的 )。
???e??我?槭颤N舊版 Flash Remoting 用得好好的要改用新版,我不知道,我也是想搞清楚這一點才?W??的。
Macromedia Flash Remoting for Flash MX 2004 ActionScript 2.0 包含下列 Class Connection DataGlue Fault FaultEvent Log NetDebug NetDebugConfig NetServices PendingCall RecordSet RelayResponder RemotingConnector Responder ResultEvent Service
Macromedia Flash Remoting for Flash MX 2004 ActionScript 2.0 包含下列 Package
mx.data.components mx.remoting mx.remoting.debug mx.rpc mx.services
原文網址: http://www.mmug.com.tw/forum/viewtopic.php?t=3683 http://www.aeu-studio.com/Charles/index.cfm?pid=200412170027
以及hiphen整理的简体版本. http://www.riacn.com/bbs/showthread.asp?postid=15307
|
|
|