AMF class mapping not working

↘锁芯ラ 提交于 2019-12-11 12:11:47

问题


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

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

This is my php class:

<?php
namespace app\web;

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

   public $stuff1;

   public $stuff2;

}

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

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

}

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


回答1:


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.

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>

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




回答2:


Did you remember to register the class?

import flash.net.registerClassAlias;

flash.net.registerClassAlias("com.site.remote.Request", Request);


来源:https://stackoverflow.com/questions/7924126/amf-class-mapping-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!