Question

I cannot access values in Flex Object (ArrayCollection) after I receive it from Zend AMF. The original type sent is PHP associative array which is simply returned like

return $this->sections['initial_setup'];

PHP Variable view:

sections array in variable view

The required result sent looks like this in Charles AMF RPC tab:

Charles proxy AMF RPC view

But when I receive the data in Flex as Object (or String[] - it doesn't matter), I cannot access the property values in such code

    var result:Object = event.result;
    if (result['database'] == 'yes' && result['admin'] == 'yes')
        // continue branch ...

and I get exception on the if-line:

    Error: Unknown Property: 'database'.
        at mx.collections::ListCollectionView ...

Finally, I can see in Eclipse variables view that ResultEvent instance carries a result of type ArrayCollection with 0 length and the values received are visible with D icon (I couldn't find what D adornment means):

ResultEvent variable

But why I still can't access them at all and what should I do to use them?

I have tried to change types of Array or ArrayCollection instead of Object. Also there is a thread discussing similar problem, but after trying that out, it doesn't help too.

Any help will be much appreciated :o)

EDIT 1: Here is the code of FB generated super class constructor for the ConfigurationService:

    // Constructor
public function _Super_ConfigurationService()
{
    // initialize service control
    _serviceControl = new mx.rpc.remoting.RemoteObject();

    // initialize RemoteClass alias for all entities returned by functions of this service

    var operations:Object = new Object();
    var operation:mx.rpc.remoting.Operation;

    operation = new mx.rpc.remoting.Operation(null, "readSettings");
     operation.resultType = Object;
    operations["readSettings"] = operation;
    operation = new mx.rpc.remoting.Operation(null, "writeSettings");
    operations["writeSettings"] = operation;
    operation = new mx.rpc.remoting.Operation(null, "readDBSettings");
     operation.resultType = valueObjects.ConnectionParams;
    operations["readDBSettings"] = operation;
    operation = new mx.rpc.remoting.Operation(null, "writeDBSettings");
    operations["writeDBSettings"] = operation;
    operation = new mx.rpc.remoting.Operation(null, "readInitSetupCompletion");
     operation.resultType = Object;
    operations["readInitSetupCompletion"] = operation;
    operation = new mx.rpc.remoting.Operation(null, "writeInitSetupCompletion");
    operations["writeInitSetupCompletion"] = operation;

    _serviceControl.operations = operations;
    _serviceControl.convertResultHandler = com.adobe.serializers.utility.TypeUtility.convertResultHandler;
    _serviceControl.source = "ConfigurationService";
    _serviceControl.endpoint = "gateway.php";


     preInitializeService();
     model_internal::initialize();
}
Was it helpful?

Solution

So what's happened here is that the Array that's serving as the source for your ArrayCollection is acting as a generic Object with those same two properties. Probably the generated code is assuming you'll always get back more than one object and is having problems when your data doesn't fulfill the assumptions Adobe's engineers made about it. One of the reasons I don't like generated code :-).

Check out these resources on how to "roll your own."

  1. Thoughts on Remoting
  2. AMFPHP to Flex Object Relational Mapping
  3. Implementing PHP Services

I think this last (3) is closest to what you probably have in PHP. If you do decide to go with a VO, you can probably just add an $explicitType to your row return and not need to change too much else on the PHP side. You'll probably need to regenerate your services if you go that route, because I suspect the generated code will be different. The good news is the Adobe engineers probably did think of the case where you have an explicit type, but only one record.

Another fix is to just check your AC for having a source of zero length that is not null and looking for your properties on the edges of that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top