Passing an Array or Object using Flash AS3 Remoting? Don't Forget the Object Encoding!

Earlier today I posted about an issue I was having when attempting to pass a structure to a ColdFusion web service using AS3 netConnection. Whenever I attempted to pass a structure to the web service, the call would be rejected before it even reached the method it was calling. The error I was receiving was

“Unknown object type tag (17)”

The Adobe documentation insisted this was possible but I tried everything I could think of with no success. There were a few developers sharing my misery but their calls for help went unanswered, and by extension, so did mine.

After spending the better part of two days tooling around with the code and searching the web, I finally hit on the solution. It derived from a combination of Oscar Trelles’ post on AS3 Flash Remoting and a post on laflash.org about AS3 and Flash Media Server. In order to pass a structure to a ColdFusion component, I had to set the netConnection’s objectEncoding to AMF0 (the default is AMF3).

I’m guessing that this qualifies as a bug since AMF0 is supposed to be for serializing AS1 and AS2 objects and AMF3 is supposed to be optimized for AS3 objects. While I was able to send simple objects, like strings and integers, to the web service using the default setting, I ran into a wall when sending an Array, Object, or Dictionary type.

Until this issue is addressed, if you’re going to be sending complex objects to a ColdFusion web service, make sure to set the object encoding to AMF0. Here’s a simple example that sends a structure containing a string to a web service. The web service then returns the string:

AS3 CODE


var myService = new NetConnection()
////////////////////////////////////////////////
//set encoding to AMF0 for complex objects
myService.objectEncoding = 0;
///////////////////////////////////////////////
myService.connect("http://www.yourdomain.com/flashservices/gateway")

var responder = new Responder(getTest_Result, onFault);
var mystruct:Array = new Array();
mystruct.mystring = "foo";
myService.call("testAPI.test", responder, mystruct);

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

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

COLDFUSION WEB SERVICE:



	
		
		
		
	


If you’re REALLY interested in objectEncoding, you can read up on it in Adobe’s livedocs .

I hope this post saves someone the two days I just blew figuring it out!

-rG

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.