【问题标题】:How to do AS3 Remoting with ColdFusion如何使用 ColdFusion 进行 AS3 远程处理
【发布时间】:2011-11-17 05:52:34
【问题描述】:

如何使用coldfusion进行远程处理,有人可以帮我吗?

我有课

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()

谁能告诉我这是怎么回事

提前致谢!

【问题讨论】:

    标签: flash actionscript-3 apache-flex coldfusion


    【解决方案1】:

    要使用冷融合进行远程处理,flex 有一个内置的方法。

    1) 您需要创建一个 Flex 项目,指定 ColdFusion 作为服务器

    2) 默认情况下,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 属性是来自 webroot 的 cf 组件的包。 例如如果 webroot 是 C:\ColdFusion8\wwwroot 并且 cfc 位于 C:\ColdFusion8\wwwroot\com\stackoverflow\testcfc.CFC 那么上面的 source 值是正确的

    4) 调用 remoteObject 方法的代码是:

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

    5) 结果处理程序会是这样的

    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 在 mxml 中(用于 flex) 要创建一个纯 ActionScript 远程对象,您只需要这样做:

    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;
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多