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

Date May 20, 2008

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’):

<cffunction name="test" output="no" access="remote" returntype="string" >
	<cfargument name="argstruct" type="any" required="no" />
	<cfset mystr =arguments.argstruct["mystring"]>
	<cfreturn  mystr />
</cffunction>

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 Responses to “Is it possible to pass a structure to ColdFusion using Flash AS3 / Remoting”

  1. Jos said:

    We had the exact same problem, and we didn’t find any solution for it. In the end we just converted the array to a long string…

    This tread had also the same problem (http://board.flashkit.com/board/showthread.php?p=3953821#post3953821). I spoke with the autor, but also no solution here.

    So if anyone can help, please :)

  2. Patrick Tai said:

    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.

  3. Patrick Tai said:

    …So you need to set it as an object in your AS

  4. Tom Chiverton said:

    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.

  5. rabidGadfly said:

    Thanks for the replies. Unfortunately, I tried Object with the same results.

    Adobe actually recommends using an Array ( http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=usingSalsaN_4.html ). The Array I use in the example is an associative array. It compiles as written. I tried strict array too and passing it as a named argument object ( {mystring:’hello’} ). All receive the same error.

  6. ejbelair said:

    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.

  7. ejbelair said:







  8. rabidGadfly said:

    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

  9. Patrick Tai said:

    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.

  10. Passing an Array or Object using Flash AS3 Remoting? Don’t Forget the Object Encoding! | rabidGadfly said:

    [...] today I posted about an issue I was having when attempting to pass a structure to a ColdFusion web service using AS3 [...]

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>