AMF 类映射不起作用 [英] AMF class mapping not working

查看:35
本文介绍了AMF 类映射不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个使用 Flex 4.5 和 Zend_AMF 作为我的 AMF 端点的应用程序.

I am building an application using Flex 4.5 and Zend_AMF as my AMF endpoint.

我想将 PHP 中名为 CRequest 的类映射到 Flex 中名为 Request 的类.

I would like to map a class called CRequest in PHP to a class called Request in Flex.

这是我的php类:

<?php
namespace app\web;

class CRequest{
   public $_explicitType = 'com.site.remote.Request';

   public $stuff1;

   public $stuff2;

}

这是动作脚本类:com.site.remote.Request

This is the actionscript class: com.site.remote.Request

package com.dreamatique.remoting
{
    [Bindable]
    [RemoteClass(alias="com.site.remote.Request")]
    public class Request
    {

        public var stuff1:String;

        public var stuff2:String;

        public function Request()
        {
        }
    }
}

作为测试,我已经让端点从 PHP 端返回一个 CRequest 实例,无论请求是什么.

As a test, I have made the endpoint return an instance of CRequest from the PHP side, no matter what the request.

然后我进行这样的远程对象调用:

I am then making a remote object call like this:

var remoteObject:RemoteObject = new RemoteObject();
remoteObject.endpoint = "http://localhost/to/my/amf/endpoint";
remoteObject.showBusyCursor = true;
remoteObject.source = 'testing';
var op:AbstractOperation = remoteObject.getOperation(null);
op.addEventListener(ResultEvent.RESULT, result);
op.send();

public static function result(event:ResultEvent):void{

    trace(event.result);
    trace(Class(getDefinitionByName(getQualifiedClassName(event.result))));
    Alert.show(event.result.toString());

}

问题是返回的结果类型为 ObjectProxy 而不是 Request.我做错了什么?

The problem is that the result comes back typed as ObjectProxy and not Request. What am I doing wrong?

推荐答案

确保您的代码库中至少有一个对该类的引用.

Ensure that you have at least one reference to the class somewhere in your codebase.

这是一个常见的陷阱,尤其是在第一次开发远程调用时,以及在任何地方的任何代码中实际使用该类型之前.

This is a common trap, especially when first developing a remote call, and before you've actually consumed the type in any code anywhere.

如果类没有被引用,它就不会被编译进来,因此不会被注册.

If the class is not referenced, it's not compiled in, and therefore, doesn't get registered.

通常,在早期开发期间,我最终会创建一个 StaticLinker 类:

Often, during early development, I'll end up creating a StaticLinker class:

public class StaticLinks
{
    private var request:Request;
}

然后在我的应用程序中引用它:

Then reference this in my application:

<s:Script>
   var linker:StaticLinks;
</s:Script>

顺便说一句 - 您之前的假设是正确的:如果您将类注释为 [RemoteObject],则不需要调用 registerClass().

BTW - you're correct in your earlier assumption: If you have annotated the class as a [RemoteObject], you're not required to call registerClass().

这篇关于AMF 类映射不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆