Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1261
  • Last Modified:

Flash CS3 AS3 remoting with ColdFusion CFC doesn't work - HELP!

I'm attempting to recreate an older Flash Remoting connection to a ColdFusion (8) CFC (which returns a query of pairs of string values) using the new type of "flash.net" connection.  It isn't working, so now I've made a function to test that simply should return "...Connection Successful" (see the CFC in the code).  It still doesn't work, and my "OnFault" function fires every time with the resuts of:

[object object]

I need to get this working for my company ASAP.  Please help!  Thanks!

Because I'm in such a hurry, I'm awarding 500 points for the correct (working / workable) answer with proper code.

Here is the ActionScript 3.0 code:
import flash.net.*;
var myservice:NetConnection = new NetConnection();
var responder:Responder = new Responder(onResult, onFault);
function onResult(responder:Object):void {
function onFault(responder:Object):void {
myservice.call("cf.myfunctions.testconnection", responder);
Here are the contents of the myfunctions.CFC:
<cfcomponent name="concerts">
<cffunction name="testconnection" access="remote" returntype="string">
<cfreturn "...connection successful">

Open in new window

  • 3
  • 2
1 Solution
Take a look at http://flexcf.com for many examples of Flex and Coldfusion communication.
vitoasaroAuthor Commented:
Jones911: Thanks, but I'm not using Flex.  I'm using Flash CS3.  I understand that the Flex communication libraries do a lot more for pulling down SQL data, but I need to make this work with Flash CS3 and AS3.
Oh sorry I miss read.
vitoasaroAuthor Commented:
I've found the answer myself after working on this for the majority of a day...
You must have the correct gateway as shown in my code.  You cannot use:

You must use:
even though BOTH gateways are operative on the ColdFusion server.
Another IMPORTANT issue is if you're testing on your LOCAL PC (as most of us do), but trying to query data from a separate web/SQL server, you need a few more things.  Let's face it: most of us develop on our PCs, but we don't all load the developer version of SQL and run a local web server on our PCs just for the sake of development.  To run on the fly in Flash CS3 without having to compile and upload a .SWF file to the server every time you want to test you'll need to have a CROSSDOMAIN.XML file in the document root of the website you're testing.  For example, if your website is http://mywebsite.com and your document root on your webserver is C:\inetpub\websites\mywebsite then that's the directory where you'll need to put the CROSSDOMAIN.XML file; It will not work for all websites if you put it in the "Default Web Site" (on IIS) directory, so don't bother.  There are three important lines in the XML file:
<site-control permitted-cross-domain-policies="all"/>
<allow-access-from domain="*" />
<allow-http-request-headers-from domain="*" headers="*" secure="false"/>
You can custom tailor these if you can figure out how to make it only allow cross-domain communication to the domains you prefer by changing the asterisks (*) to actual domains.  Since I was testing from a "non-domain" PC, it was best to leave it able to allow data to be sent everywhere (the *).   In my ActionScript 3.0 code I also added:
but this was for good measure after the above XML file made communications work.   On a side note, I read that PHP uses AMF0 to serialize it's data, but for Flash AS3 with CFC you need to use AMF3 (as you can see in my code).
Furthermore, it was a HUGE mystery for how to actually PARSE the data returned from a Coldfusion CFC query because everything I found via Google only showed examples of displaying a single string result returned from the CFC (as shown in my earlier code).  HOWEVER,  it is quite different when you need to retrieve all columns of data from a SQL query for all the rows (resultset) returned.  You need to use the very important
appended to whatever your variable object is named (the variable in between the parens of the OnResult function).  ADDITIONALLY, the data is referenced by elements within brackets.  The number in the first set of brackets refers to the ROW # of the data, and the number in the second set of brackets refers to the COLUMN NUMBER (not the name) of the data, starting with column 0, not 1, as your first column returned from a SQL query.
I took the time to collect all the data I've spent yesterday and today trying to piece together information in three different languages so that it could be found in one place for the next poor soul who is attempting to use Flash CS3 with ActionScript 3.0 to communicate with a Coldfusion CFC and retrieve SQL data.  Adobe has NO DOCUMENTATION available anywhere on their site for this, and that's just plain wrong.  For all the money I've invested in their products (thousands of dollars) I'd expect to receive some documentation PDFs that cover this information.  At LEAST they need to make it available on their website!!
Good Luck

import flash.net.*;
import flash.text.*;
import flash.events.EventDispatcher;
import flash.utils.setTimeout;
import flash.events.ErrorEvent;
import flash.events.Event;
var myservice:NetConnection = new NetConnection();
myservice.objectEncoding = ObjectEncoding.AMF3;
var responder:Responder = new Responder(onResult, onFault);  //This is triggered by a good or bad connection
function onResult(re: Object):void {  // Call this function when good data is retrieved
	var allRows:Number =re.serverInfo.totalCount;  //This sets a variable (allRows) to the total number of 							  rows returned by the query
	for(var i=0; i<allRows; i++ )  // This loops through each row of the returned recordset (query)
// The serverinfo.initialData is the key to retrieving your SQL data!!!
// The first []'s refer to the SQL ROW # of data returned
// The second []'s refer to the SQL COLUMN of data returned (starting with 0 for the first column)
// There is no data-provider feature toreference your data by column NAME, only by column NUMBER
	trace("QUERY RESULT, ROW="+i+", Column=1('performanceName'): "+re.serverInfo.initialData[i][0]);
	trace("QUERY RESULT, ROW="+i+", Column=2('ImageName'): "+re.serverInfo.initialData[i][1]);
function onFault(re:Object):void {
	var i:Object;
	for(i in re ){
	trace("Error. Didn't connect or didn't retrieve data.");
// This last line actually calls the method (the FUNCTION) in the CFC.
// Notice how this is different from AS2 because in AS3 the last thing in the quotes is the
// FUNCTION name itself.  I.e., this tells Flash to look in the cf directory for the cffunctions(.cfc) file
// and use the imagelist function in that CFC.
myservice.call("cf.cffunctions.imagelist", responder);
<cfcomponent name="concerts">
<cffunction name="imagelist" access="remote" returntype="query">		
<cfquery name="ImageList" datasource="concerts">
select performanceName, performanceImage
from ConcertsData
WHERE ((performanceImage<> '')
<cfreturn ImageList>
<?xml version="1.0"?> 
<!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd"> 
<site-control permitted-cross-domain-policies="all"/> 
<allow-access-from domain="*" /> 
<allow-http-request-headers-from domain="*" headers="*" secure="false"/> 

Open in new window

vitoasaroAuthor Commented:
The information was EXTREMELY difficult to come by, was found in only a few obscure sites on the web, and in three different languages.  I've answered it in detail here for the next unfortunate person who has trouble.

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now