Is it possible to pass a structure to ColdFusion using Flash AS3 / Remoting

UPDATE: This problem has been solved. The solution is after the post.

I’ve posted on a few forums now with no results so I’m resorting to my own blog. What I’m trying to do is pass a structure to a ColdFusion component from Flash. I’ve tried using Array, Object, and Dictionary types but it keeps failing with this error:

“Unknown object type tag (17)”

The error seems to be returned before the method is even reached suggesting that the cfc is rejecting the Remoting request altogether. I know the code is sound because I can change the structure to a string and get results back. I’ve also tried the Flash.Params method.

I’ve done a fair amount of research already, including studying Adobe livedocs which insists that it’s possible to do.

Here is my code:


loadData_btn.addEventListener(MouseEvent.MOUSE_DOWN, loadData)

var myService = new NetConnection()
myService.connect("http://localhost/flashservices/gateway/")

function loadData(evt:MouseEvent){
    var responder = new Responder(getTest_Result, onFault);
/* I've tried everything here including defining it as an Object and Dictionary. I also tried
defining it using dot notation and sending it as an object like so: {mystring:"hello"} */
	var mystruct:Array = new Array();
	mystruct["mystring"] = "hello";
	myService.call("com.mycomponent.test", responder, mystruct);
}

function getTest_Result(result){
    trace("success: "+ result);
}

function onFault( f){
	trace("There was a problem: " + f.description);
}

…and here’s my component function (I’ve tried with an argument type of ‘struct’ as well as ‘any’):



	
	
	

Thanks in advance for any help!

rG

SOLUTION: After many hours of Googling, and much trial and error, I figured out how to make this work…and it’s a one line solution. Simply add myService.objectEncoding=0 before the myService.connect line at the top. It has to do with the way objects are serialized using AMF.

10 thoughts on “Is it possible to pass a structure to ColdFusion using Flash AS3 / Remoting

  1. Try to use an Object instead of an Array in your AS code:
    var mystruct:Object= new Object();

    in AS to CF type mapping if I remember well:
    Object -> Structure
    Array -> Array;

    An array indexed with key strings does not have an equivalent in CF, it’s a structure.

  2. var mystruct:Array = new Array();
    mystruct["mystring"] = "hello";

    That compiles ?
    You don’t mean to use (say) Object there ?
    var mystruct:Object = new Object();
    mystruct["mystring"] = "hello";

    If you post a small working example, and your ‘debug’ level ColdFusion server traces to (say) CF-Talk and/or FlexCoders mailing list, you might get some other hints too.

  3. I have two Flex applications that call multiple CFC functions while passing structures with no problem.

    I create an Object to store an Associative Array as so:

    var webServiceArguments:Object =
    {
    wsArgs:
    {
    classId: CLASS_ID,
    isBlue: true
    }
    };

    Then, in the CFC I type the argument as a Structure:

    ….

    This way, I can pass any number of arguments to the CFC, without being forced to send all of them.

  4. Thanks for all the replies. The solution ended up being very simple, though the time put into finding it was maddening. Simply add myService.objectEncoding=0 before the myService.connect line at the top of the AS code. It controls the way objects are serialized using AMF.

    rG

  5. I was about to suggest you to put this line.
    NetConnection.defaultObjectEncoding = 0;
    You won’t need to set this value for any new instantiation of a NetConnection after you have put this in place.

Comments are closed.