<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>rabidGadfly &#187; objectEncoding</title>
	<atom:link href="http://rabidgadfly.com/tag/objectencoding/feed/" rel="self" type="application/rss+xml" />
	<link>http://rabidgadfly.com</link>
	<description>Simple Solutions to Nagging Coding Problems</description>
	<lastBuildDate>Wed, 19 Oct 2011 13:43:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Passing an Array or Object using Flash AS3 Remoting? Don&#039;t Forget the Object Encoding!</title>
		<link>http://rabidgadfly.com/2008/05/passing-an-array-or-object-using-flash-as3-remoting-dont-forget-the-object-encoding/</link>
		<comments>http://rabidgadfly.com/2008/05/passing-an-array-or-object-using-flash-as3-remoting-dont-forget-the-object-encoding/#comments</comments>
		<pubDate>Tue, 20 May 2008 20:12:35 +0000</pubDate>
		<dc:creator>rabidgadfly</dc:creator>
				<category><![CDATA[flash]]></category>
		<category><![CDATA[amf]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[coldFusion]]></category>
		<category><![CDATA[objectEncoding]]></category>
		<category><![CDATA[remoting]]></category>

		<guid isPermaLink="false">http://www.rabidgadfly.com/?p=65</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>Earlier today <a href="http://www.rabidgadfly.com/?p=64">I posted about an issue</a> 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</p>
<p>&#8220;Unknown object type tag (17)&#8221;</p>
<p>The <a href="http://livedocs.adobe.com/coldfusion/8/htmldocs/usingSalsaN_4.html">Adobe documentation</a> insisted this was possible but I tried everything I could think of with no success. There were a few <a href="http://www.google.com/search?q=%22Unknown+object+type+tag+(17)%22&#038;ie=utf-8&#038;oe=utf-8&#038;aq=t&#038;rls=org.mozilla:en-US:official&#038;client=firefox-a">developers sharing my misery</a> but their calls for help went unanswered, and by extension, so did mine.</p>
<p>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 <a href="http://oscartrelles.com/archives/as3_flash_remoting_example">Oscar Trelles&#8217; post</a> on AS3 Flash Remoting and a <a href="http://www.laflash.org/node/560">post on laflash.org</a> about AS3 and Flash Media Server. In order to pass a structure to a ColdFusion component, I had to set the netConnection&#8217;s objectEncoding to AMF0 (the default is AMF3).</p>
<p>I&#8217;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.</p>
<p>Until this issue is addressed, if you&#8217;re going to be sending complex objects to a ColdFusion web service, make sure to set the object encoding to AMF0. Here&#8217;s a simple example that sends a structure containing a string to a web service. The web service then returns the string:</p>
<p>AS3 CODE</p>
<pre><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);
}
</code></pre>
<p>COLDFUSION WEB SERVICE:<br />
<code>
<pre>
<cfcomponent>

	<cffunction name="test" output="no" access="remote" returntype="any" >
		<cfargument name="argstruct" type="any" />
		<cfset mystr1 =argstruct["mystring"]>
		<cfreturn  mystr1 />
	</cffunction>

</cfcomponent>
</pre>
<p></code></p>
<p>If you&#8217;re REALLY interested in objectEncoding, you can <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/ObjectEncoding.html">read up on it in Adobe&#8217;s livedocs</a> .</p>
<p>I hope this post saves someone the two days I just blew figuring it out!</p>
<p>-rG</p>
]]></content:encoded>
			<wfw:commentRss>http://rabidgadfly.com/2008/05/passing-an-array-or-object-using-flash-as3-remoting-dont-forget-the-object-encoding/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Is it possible to pass a structure to ColdFusion using Flash AS3 / Remoting</title>
		<link>http://rabidgadfly.com/2008/05/is-it-possible-to-pass-a-structure-to-coldfusion-using-flash-as3-remoting/</link>
		<comments>http://rabidgadfly.com/2008/05/is-it-possible-to-pass-a-structure-to-coldfusion-using-flash-as3-remoting/#comments</comments>
		<pubDate>Tue, 20 May 2008 14:57:15 +0000</pubDate>
		<dc:creator>rabidgadfly</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[coldFusion]]></category>
		<category><![CDATA[remoting]]></category>
		<category><![CDATA[amf]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[netconnection]]></category>
		<category><![CDATA[objectEncoding]]></category>

		<guid isPermaLink="false">http://www.rabidgadfly.com/?p=64</guid>
		<description><![CDATA[UPDATE: This problem has been solved. The solution is after the post. I&#8217;ve posted on a few forums now with no results so I&#8217;m resorting to my own blog. What I&#8217;m trying to do is pass a structure to a ColdFusion component from Flash. I&#8217;ve tried using Array, Object, and Dictionary types but it keeps [...]]]></description>
			<content:encoded><![CDATA[<p><strong>UPDATE:</strong> This problem has been solved. The solution is after the post.</p>
<p>I&#8217;ve posted on a few forums now with no results so I&#8217;m resorting to my own blog. What I&#8217;m trying to do is pass a structure to a ColdFusion component from Flash. I&#8217;ve tried using Array, Object, and Dictionary types but it keeps failing with this error:</p>
<p>&#8220;Unknown object type tag (17)&#8221;</p>
<p>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&#8217;ve also tried the Flash.Params method.</p>
<p>I&#8217;ve done a fair amount of research already, including studying <a href="http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=usingSalsaN_4.html">Adobe livedocs</a> which insists that it&#8217;s possible to do.</p>
<p>Here is my code:</p>
<pre><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);
}
</code></pre>
<p>&#8230;and here&#8217;s my component function (I&#8217;ve tried with an argument type of &#8216;struct&#8217; as well as &#8216;any&#8217;):</p>
<pre><code>
<cffunction name="test" output="no" access="remote" returntype="string" >
	<cfargument name="argstruct" type="any" required="no" />
	<cfset mystr =arguments.argstruct["mystring"]>
	<cfreturn  mystr />
</cffunction>
</code></pre>
<p>Thanks in advance for any help!</p>
<p>rG</p>
<p><strong>SOLUTION:</strong> <em>After many hours of Googling, and much trial and error, I figured out how to make this work&#8230;and it&#8217;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. </em></p>
]]></content:encoded>
			<wfw:commentRss>http://rabidgadfly.com/2008/05/is-it-possible-to-pass-a-structure-to-coldfusion-using-flash-as3-remoting/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

