Solved

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

Posted on 2009-03-29
5
1,201 Views
Last Modified: 2013-12-20
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.*;

flash.system.Security.allowDomain("*");
 
 

var myservice:NetConnection = new NetConnection();

myservice.connect("http://mywebsite.com/flex2gateway");
 

var responder:Responder = new Responder(onResult, onFault);
 

function onResult(responder:Object):void {

 trace(responder);

 mytext.text="Success!!!";

}
 

function onFault(responder:Object):void {

trace(responder);

trace("Error");

mytext.text="Error...";

}
 

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">

</cffunction>

</cfcomponent>

Open in new window

0
Comment
Question by:vitoasaro
  • 3
  • 2
5 Comments
 
LVL 19

Expert Comment

by:Jones911
Comment Utility
Take a look at http://flexcf.com for many examples of Flex and Coldfusion communication.
0
 

Author Comment

by:vitoasaro
Comment Utility
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.
0
 
LVL 19

Expert Comment

by:Jones911
Comment Utility
Oh sorry I miss read.
0
 

Accepted Solution

by:
vitoasaro earned 0 total points
Comment Utility
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:
myservice.connect(http://mywebsite.com/[b]flex2gateway[/b]);

You must use:
myservice.connect(http://mywebsite.com/[b]flashservices/gateway[/b]);
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:
flash.system.Security.allowDomain("*");
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
.serverInfo.initialData
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



ACTIONSCRIPT 3.0 Code:

-------------------------------

import flash.net.*;

import flash.text.*;

import flash.events.EventDispatcher;

import flash.utils.setTimeout;

import flash.events.ErrorEvent;

import flash.events.Event;

	

flash.system.Security.allowDomain("*");
 

var myservice:NetConnection = new NetConnection();

myservice.objectEncoding = ObjectEncoding.AMF3;
 

myservice.connect("http://mywebsite.com/flashservices/gateway");
 

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;

	

	trace(re);
 

	for(i in re ){

		trace(re[i]);

	}
 

	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);
 
 

=======================================================================
 
 

COLDFUSION CFC CODE (this file is called CFCFUNCTIONS.CFC):

-----------------------------

<cfcomponent name="concerts">

<cffunction name="imagelist" access="remote" returntype="query">		

<cfquery name="ImageList" datasource="concerts">

select performanceName, performanceImage

from ConcertsData

WHERE ((performanceImage<> '')

</cfquery>

<cfreturn ImageList>

</cffunction>
 
 

========================================================================
 

CROSSDOMAIN.XML FILE CONTENTS:

----------------------

<?xml version="1.0"?> 

<!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd"> 

<cross-domain-policy> 

<site-control permitted-cross-domain-policies="all"/> 

<allow-access-from domain="*" /> 

<allow-http-request-headers-from domain="*" headers="*" secure="false"/> 

</cross-domain-policy> 

</cfcomponent">

Open in new window

0
 

Author Comment

by:vitoasaro
Comment Utility
PLEASE MARK MY OWN COMMENTS AS A VALID ANSWER TO THIS QUESTION.
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.
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now