2011-11-17 3 views
0

coldfusionを使用してリモート処理を行う方法誰かを助けてくれますか?ColdFusionでAS3リモーティングを行う方法

私はクラス

package 
{ 
import flash.display.*; 
import flash.events.*; 
import flash.net.*; 

public class Remoting extends MovieClip 
{ 
    private var rs:NetConnection; 

    public function Remoting():void 
    { 
     call_mc.buttonMode=true; 
     call_mc.useHandCursor=true; 
     call_mc.addEventListener(MouseEvent.CLICK, OnClick); 
    } 

    private function OnClick(e:MouseEvent):void 
    { 
     rs = new NetConnection("http://localhost/amfphp/gateway/"); 
     var responder:Responder = new Responder(onResult, onFault); 
     rs.call("HelloWorld.SayHello", responder); 
    } 

    private function onResult(result:Object):void 
    { 
     trace(result); 
    } 

    private function onFault(fault:Object):void 
    { 
     trace(fault); 
    } 
    }  
} 

エラーが

  Error opening URL 'http://localhost/amfphp/gateway/' 
      Error #2044: Unhandled NetStatusEvent:. level=error, code=NetConnection.Call.Failed 
at Remoting/OnClick() 

誰もがいただきました!事前にこの

おかげで間違って教えてもらえますが発生しています!

答えて

2

coldfusionでリモート処理を行うには、flexが組み込まれています。

1)あなたは、サーバー

enter image description here

2としてColdFusionを指定するFlexプロジェクトを作成する必要があります)ColdFusionサーバーは、デフォルトでは、Flashリモーティングに必要なすべての記述子ファイルを持つことになります。

3)RemoteObjectsは、CFコンポーネント

<s:RemoteObject destination="ColdFusion" 
    source="com.stackoverflow.testcfc" 
    showBusyCursor="true" 
    id="ro"> 
     <s:method name="myFunction" 
      result="method1_resultHandler(event)"> 
       <s:arguments> 
        <arg1 /> 
        <arg2 /> 
        <!-- and so on --> 
       </s:arguments> 
     </s:method> 
</s:RemoteObject> 

sourceプロパティがウェブルートからのCFコンポーネントのパッケージであるとの通信に使用されます。例:

protected function sendRequest(event:FlexEvent):void { 
    var op:AbstractOperation=ro.getOperation("myFunction"); 
    op.arguments={arg1: "someValue", arg2: 100}; 
    op.send(); 
} 

5)結果ハンドラは次のようになりますウェブルートはC:\ColdFusion8\wwwrootであり、CFCはC:\ColdFusion8\wwwroot\com\stackoverflow\testcfc.CFCに位置しているならば、sourceの上記値は

4)コードは、RemoteObjectのメソッドは次のようになり呼び出すために正しいであろう

protected function method1_resultHandler(event:ResultEvent):void { 
    //return value of cffunction in event.result 
    event.result; 
} 

6)のようなCFCは

<cfcomponent> 
    <cffunction name="myFunction" access="remote" returntype="string"> 
     <cfargument name="arg1" type="string" required="yes"> 
     <cfargument name="arg2" type="numeric" required="yes"> 
     <cfreturn arg1 & ToString(arg2)> 
    </cffunction> 
</cfcomponent> 
のようになります。

私が作成したRemoteObjectは、純粋のActionScriptのRemoteObjectを作成するための (フレックス用)MXMLである EDIT、あなただけのこれを実行する必要があります。

var ro:RemoteObject=new RemoteObject("ColdFusion"); 
ro.showBusyCursor=true; 
ro.source="com.stackoverflow.testcfc"; 
var op:AbstractOperation=new AbstractOperation(null, "myFunction"); 
op.addEventListener(ResultEvent.RESULT, method1_resultHandler); 
if(!ro.operations) { 
    ro.operations={}; 
} 
ro.operations["myFunction"]=op; 
+0

がどのようにフラッシュAS3でこれを行うには? –

+0

詳細については、http://help.adobe.com/en_US/flashbuilder/using/WSe4e4b720da9dedb5-1a92eab212e75b9d8b2-7f9d.htmlを参照してください。 –

+0

@SwatiSingh純粋なAS3メソッドはFlash用です –

関連する問題