سؤال

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?

هل كانت مفيدة؟

المحلول

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

نصائح أخرى

Did you remember to register the class?

import flash.net.registerClassAlias;

flash.net.registerClassAlias("com.site.remote.Request", Request);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top