Saturday, March 31, 2007

RemoteObject Mapping... again

Ok... I'm posting this as a checklist of possible reasons why an Actionscript object will not properly map to a ColdFusion CFC (or Java object for that matter). I just went through about thirty minutes of debugging trying to track down why I was getting an array of generic Actionscript objects instead of my custom objects. I seem to run into this fairly often. : )

1. Did not include [RemoteClass(alias="YourObjectPath")] in the Actionscript class.
2. Did not import the Actionscript class into the application.
2. Did not include an instance of the Actionscript class into the application.
3. Did not have the same number and name of properties on both the Actionscript object and the server side object.
4. Have import statements after the RemoteClass alias metadata. (This is what happened to me tonight... oops!)

If you can think of something I've missed let me know so I can update the list.

5 comments:

Anonymous said...

The path to the CFC alias is case sensitive - see:
http://www.brucephillips.name/blog/index.cfm/2007/3/17/Solving-A-Problem-In-Relating-An-ActionScript-Class-To-A-ColdFusion-CFC

Anonymous said...

Hi Pat

Thanks for the checklist. I too have had simular issues. However, now I have a different problem - with extended actionscipt/CFC mappings using remoteObject.

The base class properties are not returned at all. The inherited object properties maps fine.

It seems to be a issue with CFC strong typed objects (AMF0) only....becuase testing with WSDL(soap) returns the base class and inheritied class properties fine...any ideas.
(Have looked high and low for some kind of a solution....)

My said...

I am using OpenAMF for Flex to Java communication. I have ActionScript Value Objects which are equivalent of my Java Value Objects. I am not putting [RemoteClass(alias=" in my AS file and still I am being able to transfer objects both ways. Also in my AS Value Object I have to make all the variable start with "_" (underscore). If I don't do that java object values are not set on AS object. Can anyone explain this behavior ?

papercrane said...

You are correct that an import only is not enough to include a class in the AS compilation but the only option is not an instance of the variable. A declaration of a variable (with no instance) is sufficient as well as n instance of the Class object for the type. This is my preferred method, actually.

import Class1;
import Class2;

...

private static const CLASSES : Array =
[
Class1,
Class2
];

Pat Smitherman said...

@papercrane - Cool, I'll have to try that. Another technique I've seen is to use the registerClassAlias method to register the classes used in the application. This would get around using dummy variables as well.