Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2009-03-29
5
Medium Priority
?
1,245 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 19

Expert Comment

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

Author Comment

by:vitoasaro
ID: 24014936
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
ID: 24014945
Oh sorry I miss read.
0
 

Accepted Solution

by:
vitoasaro earned 0 total points
ID: 24016371
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
ID: 24016380
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

Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

610 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