Jul
29

Remoting for ColdFusion Flash Forms

126 comments Posted by: Laura

We had given for granted that it was not possible to use Flash Remoting with ColdFusion Flash Forms because of the ActionScript language restrictions that they have. All workarounds used external .swf loaded into the form, so we never used them and we never investigated any further. Otherwise, we would’ve found that there is a simple way to get remoting in ColdFusion Flash Forms sooner. In any case, here it is, better late than never. Note that this does not use external swf and therefore it is not a hack.

As an introduction, we made a simple example in which we call a cfc that returns a formatted string according to the parameter passed.

<cfsavecontent variable="getData">
   //create connection, replacing the gateway url with yours

   var connection:mx.remoting.Connection =
      mx.remoting.NetServices.createGatewayConnection(
         "http://www.example.com/flashservices/gateway/");
   //declare service

   var myService:mx.remoting.NetServiceProxy;
   
   //put the controls in scope to avoid calling _root

   var mask = mask;
   var display = display;
   
   //make an object that will handle the response

   var responseHandler = {};
   
   //function that receives the response
   responseHandler.onResult = function( results: Object ):Void {
      //when results are back, we show the text received
      display.text = results;
   }

   //function that receives any error that may have occurred during the call

   responseHandler.onStatus = function( stat: Object ):Void {
      //if there is any error, show an alert

      alert("Error while calling cfc:" + stat.description);
   }
   
   //get service. First parameter is path to component and the second it's the object that will handle the response

   myService = connection.getService("blog.examples.flashRemotingResponder", responseHandler );
   //make call, passing one parameter
   myService.getDate(mask.text);
</cfsavecontent>

<!--- then the form --->
<cfform name="myform" format="Flash">
   <cftextarea type="text" name="mask" label="Mask">mmmm dd of yyyy
hh:mm:ss</cftextarea>
   <cfinput type="text" name="display" label="Result" />
   <cfinput type="Button" name="getDataBtn" value="Get Date" onclick="#getData#" />       
</cfform>

This is what the cfc does, as you can see it’s a very simple function.

<cffunction name="getDate" output="false" description="Returns the current time" access="remote" returntype="string">
   <cfargument name="mask" required="false" type="string" default=""/>

      <!--- get the current time --->
      <cfset var time = now() />
            
      <cfif len(arguments.mask)>
         <!--- format the date according to mask --->
         <cfset time = dateformat(time,arguments.mask) />
      </cfif>
      
      <cfreturn time />
</cffunction>

A live example
Download the source

A couple of notes on Remoting:
The component that you call has to be web accessible for the Remoting gateway to find it, just like when you create a web service, and the method has to have access="remote".

The path to the component is the directory structure as viewed from the root of your website, separated by dots, followed by the component name. For example, if your component is located at http://www.example.com/somedir/components/myComponent.cfc, then the path would be somedir.components.myComponent

That being said, I never have my components in the root of my website, but in a mapping called com, where I have directories with the names of my domains. I then call my components com.blueinstant.somepackage.myComponent

This, however, won’t work with remoting, so what I do is create a façade component that exposes only the methods that flash needs, and can even format the data specifically for flash, separating this from my other components that know nothing about the views. In addition, from that component I can enforce security or call an already instantiated object that I keep in a shared scope.

Lastly, the documentation warns that Application.cfc should not implement the “onRequest” method if we have “any CFC files that are intended to be accessed as web services, using Flash Remoting, or using an event gateway”

Category: CFForm | ColdFusion | Flash Remoting |

126 Comments so far

Write yours
Brian Sloan
1. Brian Sloan wrote on July 29, 2005 at 6:04 AM
Where is the flashservices directory supposed to be? It looks like it is supposed to be in the wwwroot directory from the cgi.http_host var in the download. Also, does CF come with flashservices or do I need to download it from macromedia?
Brian Sloan
2. Brian Sloan wrote on July 29, 2005 at 6:31 AM
Nevermind... It seems to work as is. I just tested it out on our server and it worked great. Thanks, this is going to make life way easier. Currently I have screens with 2 grids and the 2nd is dependent on the first. Before this I had to execute both queries and save the 2nd grids in a global var then clear it.
Philippe
3. Philippe wrote on July 29, 2005 at 6:53 AM
So, mx.remoting.Connection comes from the Flex packages, right?
Brian Sloan
4. Brian Sloan wrote on July 29, 2005 at 7:08 AM
There seems to be a couple of problems implementing this with my app.

1. Does the cfc have to be in the root of site? It appears it does and all mine are under a components directory. Is there any way around this or do I have to put the cfc in the root?

2. If my application.cfc file is present I get an event handler exception. It appears something in it is stopping the flash remoting from working. Any ideas or solutions to this problem? I need the application.cfc for security reasons.
Steve Walker
Brian,

I don't know if this will help in your scenario, but I point to my components in the Application.cfc file (e.g. &lt;cfset Request.libcfc = root.folder.file&gt;) and then using their example :
myService = connection.getService(&quot;&lt;cfoutput&gt;#REQUEST.libcfc#&lt;/cfoutput&gt;&quot;, responseHandler );

and everything works fine
Steve Walker
1. I should clarify. Where I put root.folder.file, root is actually a folder under the root of my domain which is a completely separate website. The dot notation should represent the folder structure of your site (e.g. folder.file).

2. Is there a way to present an empty grid without using queryNew()? Having to do this sort of defeats the purpose of using reusable components.
Brian Sloan
7. Brian Sloan wrote on July 29, 2005 at 9:43 AM
Steve,

Thanks... I will try putting them under a completely different site. As far as I know you need the queryNew at this point for the grid to function. If there is no query= in the grid tag you can not add rows.
Brian Sloan
8. Brian Sloan wrote on July 29, 2005 at 11:42 AM
Now I am getting some where. Now I have the data populating on the 2nd grid when the 1st grid is clicked. However, I can't seem to manipulate the data now. The filters wont work and without using dataProvider.addItem the grid is undefined so cfgridupdate wont work. Any ideas?

Thanks,
Brian
Steve Walker
Okay, so I saw the updated information that says not to use the onRequest method. The CF7 documentation says not to because MX won't process the request. I did use the onRequest method and I do have my cfc buried in my components folder. Everything works fine, so is that a bug, is there something amiss in the documentation, or are there security concerns that aren't addressed?
Todd
10. Todd wrote on July 29, 2005 at 4:48 PM
This has to be the coolest thing i've ever seen. One question though, like others, i'm losing all binding capabilities when i use this. Also, I had a tree populated by the same original query that is not working now either....:(
Pedro Claudio
11. Pedro Claudio wrote on July 30, 2005 at 5:32 AM
Congratulations!
WebService,HTTPService,RemoteObject
Laura
Philippe,
the class mx.remoting.Connection
is a Flash remoting class, not specifically Flex. It does come with Flex, since Flash Forms use the remoting packages.
Was that your question?
Nahuel
Todd,
I don't know why you don't have bindings anymore. I would suggest you to check the column names of your data.
Pedro Claudio
14. Pedro Claudio wrote on August 01, 2005 at 1:46 AM
I stow to some time making tests as this, now not. I investigated in the WEB-INF/cfform folder the packages to jar and the package swc and what more it called the attention was the package swc for class that they are not in system_classes, as:
mx.core.*
mx.charts.*
mx.Remotig.*
mx.Service.W*
mx.Service.*
mx.servicetags.*
Philippe Maegerman
Laura,
I was just wondering how you did find out about these classes, no doc I guess?
Todd
16. Todd wrote on August 01, 2005 at 6:25 AM
Nahuel,

I'm sure I'm doing something wrong, but bindings are still not working. I thought I'd try your source code since I may have goofed my column names, and still no luck. Here is my code - the only thing I added to your example was the bound text box:

&lt;cfform name=&quot;myform&quot; height=&quot;350&quot; width=&quot;400&quot; format=&quot;Flash&quot; timeout=&quot;300&quot; &gt;
   &lt;cfgrid name=&quot;contactList&quot; query=&quot;memberList&quot; height=&quot;200&quot; rowheaders=&quot;false&quot;&gt;
         &lt;cfgridcolumn name=&quot;name&quot; header=&quot;Name&quot; /&gt;
         &lt;cfgridcolumn name=&quot;age&quot; header=&quot;Age&quot; /&gt;
         &lt;cfgridcolumn name=&quot;gender&quot; header=&quot;Gender&quot; /&gt;
   &lt;/cfgrid&gt;
   &lt;cfinput type=&quot;button&quot; name=&quot;getValues&quot; value=&quot;Populate data grid&quot; onClick=&quot;#getData#&quot;&gt;
   &lt;cfinput type=&quot;text&quot; name=&quot;test&quot; bind=&quot;{contactList.dataProvider[contactList.selectedIndex]['name']}&quot;&gt;
&lt;/cfform&gt;

Thanks for any possible advice you may be able to give. Keep up the amazing work - I really hope you guys are making some money off this - You really deserve it!
Steve Walker
Todd,

Try:
bind=&quot;{(contactList.selectedItem.name ==undefined)?'':contactList.selectedItem.name}&quot;

It is working for me. The first part ensures that the field is blank instead of the word undefined.
Todd
18. Todd wrote on August 01, 2005 at 7:30 AM
now THAT works....thanks Steve - you're the man!
Paul Roe
19. Paul Roe wrote on August 01, 2005 at 10:26 AM
I am just running CFMX7.0 can I make use of Flash Remoting or do I need to buy Flex or the actual Flash Remoting product that MM sells?
Nahuel
Hi Paul,
You don't need to buy anything. ColdFusion already comes with Remoting :)
Paul Roe
21. Paul Roe wrote on August 01, 2005 at 10:54 AM
Well then what do I have to configure to get this working. I get the following errors:

Error /CFIDE/scripts/cfform.swc
Unable to resolve library location.

Error /cfgrid-remoting.cfm:4
Unable to load runtime shared libraries.

Does Flash remoting require any setup?
Laura
Paul,
Remoting setup is not the problem, at least not yet. Your Flash forms do not work because you don't have the cfide folder web accessible. You can either copy the CFIDE folder (without the administrator if you don't need it) to your web root or make a virtual directory pointing to it.

Hope that helps
Paul Roe
23. Paul Roe wrote on August 01, 2005 at 12:45 PM
Thanks for the help so far guys, but I'm still having issues. If you have it in you to help me further, please email me at paul (dot) roe (at) gmail (dot) com.
CarlosM()
24. CarlosM() wrote on August 02, 2005 at 7:45 AM
This is exactly what I've been waiting for MM to do in its’ next release! NO NEED to wait now...

OK, here’s my question….

I'm running CFMX7 Standard w/Apache2 on Suse9ENT , can I still do the remoting or do I need CFMX7Ent running on a Java Server???

Now I was able to get:
CFMX7ENT .WAR running with TomCat4 with the Apache hook on SuSe9Ent but I had problems with the RDS so I went back to the CF Standard Edition. Is this going to haunt me?
Marcus
How do you send multiple parameters to the cfc with action script.
CarlosM()
26. CarlosM() wrote on August 02, 2005 at 9:09 AM
It works in CFMX7 Standard! I got the grid to populate with my own query in a CFC.

Isn't it great when thing just work.

Ok, I hope I'm not asking too much but is it possible to create a custom tag for this?
Nahuel
Marcus,
Yes, you can pass as many as you want.

Carlos,
We'll add that to the wish list :)
Neil Bailey
I am sure this is a newbie question (as I am a 'remoting' newbie), but its literally killing me. I am to call the CFC, no problem. I can get the results back, no problem. But the CFC is returning a struct, and we want to take that data and return it to multiple fields.

Also, the object that gets passed into onResults - I can't find ANYTHING on this object. Does anyone know where I can see soms docs on this?
Neil Bailey
Nahuel,

Thanks - I actually managed to figure this out, too (this one on my own!) Actionscript won't take a structure back (at least according to the docs), but it WILL take an array. So, I got it straightened out. Thank you again for your help, and keep up the good work.
Marcus
Nahuel, can you give me an example of how to send multiple parameters?

Thx
Marcus
Nahuel: Please disregard my previous post, I'm an idiot for not looking at the live docs.

Marcus
Laura
Neil,
ActionScript does take structures back. We use it all the time. In fact, we use it the MXNA application (check mxna.cfc for example). All of the functions there return structures, not plain queries. The problem you must have had is the case in the structure. When you create a structure and set up the keys as myStruct.key1, CF will make it uppercase, myStruct.KEY1. Because ActionScript is case sensitive, it will not find it.
In order to keep your desired case, you must create your structure keys as
&lt;cfset myStruct[&quot;key1&quot;] = &quot;&quot; /&gt;
&lt;cfset myStruct[&quot;msg&quot;] = &quot;&quot; /&gt;

and so on.
Kola
Guys
I've really just started putting flash forms through their paces (while learning flash at the same time). Question I have is does anyone envisage this being disabled in anyway in one of the new releases? I imagine that MM didn't really want cfdevelopers to be able to utilise remoting in this way and would rather we all use flash?
Kola
sorry meant to say rather we all use flash or flex :)
Neil Bailey
Thanks, Laura, I am going to go through that now! In the meantime, another question (hopefully the last one). Can I (quickly and easily) pass the entire form to a CFC, or do I need to specify each field, one value at a time?
Neil Bailey
Laura,

I am literally pulling my hair out here! I simply cannot get the actionscript code in the main page to see the values returned in a structure.... I created the struct in the CFC as you suggested above, and at this point........ haha I'm sure you've been at this point once or twice..

responseHandler.onResult = function( results: Object ):Void {
   //when results are back, populate the data fields
   _root.first_name.text = results.first_name;
   }

PLEASE let me know what I am doing wrong here.....
Liz
38. Liz wrote on August 16, 2005 at 10:58 AM
What is the correct syntax to get the query result set from the responseHandler?

I currently call my myservice.getProduct ({spc_product_code_id:oi_product1.value}) which should return a row of data. This is my component function:
&lt;cffunction name=&quot;getProduct&quot; output=&quot;Yes&quot; returntype=Query access=&quot;remote&quot;&gt;
&lt;cfargument name=&quot;spc_product_code_id&quot; type=&quot;String&quot; required=&quot;True&quot;&gt;
&lt;cfquery name=&quot;getdata&quot; datasource='#DataBse#' timeout='30'&gt;
   select SPC_PRODUCT_CODE_ID,
      SPC_PRODUCT_NAME,
      SPC_UNIT_PRICE_MN,
      SPC_ACCTG_CODE_ID
    from T_SUPP_PRODUCT_CODES WITH (NOLOCK)
    where SPC_PRODUCT_CODE_ID = #val(spc_product_code_id)#
   Order by SPC_PRODUCT_NAME
&lt;/cfquery&gt;
&lt;cfreturn getdata&gt;   
&lt;/cffunction&gt;
(The query works fine non-remotely.)
However, when I try to access the results from the responseHandler I get garbage displayed in my oi_price1.text display field.

responseHandler.onResult = function( results: Object ):Void {
oi_price1.text = results.spc_unit_price_mn;
}

What is the correct syntax to access the data returned in the results variable? Please help!
Liz
Neil Bailey
Liz, i am having LITERALLY the EXACT same issue. I can't access the individual elements of either a query or a structure. If you come up with a solution, please let me know - I have been pulling my hair our for two days over this!

Laura
Liz and Neil,
It is not the same if you are returning a structure than a query. If you return a structure, this should work as long as the case is correct:
oi_price1.text = results.spc_unit_price_mn;
if you are returning a query, then you receive a recordset in flash, which has its own syntax for accessing the elements. In your example above, you can access it as:
var record = results.getItemAt(0);
_root.oi_price1.text = record.spc_unit_price_mn;

or simply
_root.oi_price1.text = results.getItemAt(0).spc_unit_price_mn;

but make sure spc_unit_price_mn has the correct case. It should be like it is in your db (is it all caps?)
Neil Bailey
I am setting the value of a text field to the results object, just to see what is getting returned; its just a comma seperated list. In the CFC, the return type is a struct, I am setting the CF struct keys the way you specified (to ensure the proper case), but when I try to access results.structKeyName (in ANY fashion - I have tried results.name, results.NAME, results['name'] and results['NAME'] - nothing is working), I get 'undefined'.

However, when I access results[0] I get the first value. Go figure.......
Liz
42. Liz wrote on August 16, 2005 at 11:51 AM
Laura, you are a goddess! results.getItemAt(0) worked! Thank you, thank you, thank you! Where did you find this informaion?
Neil Bailey
I am setting the value of a text field to the results object, just to see what is getting returned; its just a comma seperated list. In the CFC, the return type is a struct, I am setting the CF struct keys the way you specified (to ensure the proper case), but when I try to access results.structKeyName (in ANY fashion - I have tried results.name, results.NAME, results['name'] and results['NAME'] - nothing is working), I get 'undefined'.

However, when I access results[0] I get the first value. Go figure.......
Neil Bailey
sorry about the double post :-(
Neil Bailey
My apologies! Case in point: NEVER trust what ANYONE tells you! &quot;Oh, yes the CFC is DEFINITELY returning a query!&quot; or &quot;Oh, yes, the CFC is DEFINITELY returning a struct!&quot; Couldn't POSSIBLY be returning the ARRAY that i found in the returntype of the CFC code! Dumbass......

Anyway, last question, is there anyway to pass the entire form to a CFC?
Aaron Longnion
when I click on the Get Date button, I get &quot;Error while calling CFC:Service threw an exception during method invocation: No service named flashRemotingResponder is known to Flash Remoting MX.&quot; Both files in the download are in the web root.

/flashservices/gateway/ should be correct for my site. I was told if I go to [mySite]/flashservices/gateway/ and I get a blank page, then that confirms that the directory is correct...

What am I doing wrong?
Jock S
47. Jock S wrote on August 22, 2005 at 3:20 PM
Is it possible to update Flash Forms with new data with remoting in &quot;real time&quot; or without requiring the user to push some sort of Update button? Thanks.
Neil Bailey
Jock,

I would think you would be able to do something with the setInterval function.... have it call a CFC, which returns whatever, every.....however often....

This is the way I would start. Course, I am fairly far down the totem pole when it comes to experience......
Joe
49. Joe wrote on August 23, 2005 at 7:24 AM
Has anyone figured out how to pass form fields back to a cfc by using remoting?
Philippe Maegerman
I guess it's gonna be
myService.myMethod(field.text,combo.selectedItem.label,...);
Then in your CFC, you declare them as arguments:
&lt;cfargument name=&quot;field1&quot;&gt;
&lt;cfargument name=&quot;field2&quot;&gt;
...
Joe
51. Joe wrote on August 23, 2005 at 8:53 AM
Thanks Philippe.

Anyone have a good example of how to parse through a ColdFusion query recordset in actionscript? I'm getting the query from a cfc call (remoting).
Philippe Maegerman
for(var i=0; i&lt;recordset.getLength();i++){
... recordset.getItemAt(i).PROPERTY
}
Chip Mayan
54. Chip Mayan wrote on August 25, 2005 at 1:17 PM
This is exactly what i was looking for! I had heard and read that you couldn't do remoting from a CF7 Flash Form because that is how Macromedia was trying to seperate CF7 from Flex. The only problem I had was trying to send a structure to a cfc. You cannot declare a &quot;new&quot; object as the new keyword is blocked by the server. CF returns an error. So, it isn't like flex. So, if anyone knows how to pass a structure to a cfc then please let me know. Thanks a bunch!
Neil Bailey
Chip,

I asked the exact same question above. In the cfc, instead of setting the structure up as structName.keyName = whatever, set it as structName[&quot;keyName&quot;] = whatever. Then in the cfSaveContent variable, access it as result.keyName.

You need to do it like this to preserve case-sensitivity. As will not see results.keyName if ColdFusion returns it as results.KEYNAME or results.keyname or whatever.

I had a LOT of trouble getting through this, but make sure your CFC has a return type set to struct, make sure that you set your structure keys correctly in the CFC, and you shouldn't have any problems.
Stephen Moretti
I'm getting a problem calling my cfc. I can invoke it from a CF page and I can see the cfc in the component browser in dwmx, the CF Component browser and if I call the cfc using the createEmptyMovieClip hack, but if I try to use the cfcexplorer in CFAdmin I get &quot;The component definition file for component 'wms05.orders.OrderForm' cannot be found on this server.&quot; and I get &quot;not found&quot; from the call in cfform.

wms05 is a CF Mapping to the appropriate folder.
The &quot;flashservices/gateway&quot; folder exists.

Here's a snippet of the actionscript :

//set variables
var AccountNo = '#session.User.AccountNo#';
var dsn = &quot;myDSN&quot;;

//get service
myService = connection.getService(&quot;wms05.orders.OrderForm&quot;, responseHandler );
//make call
myService.getCarriage(dsn,AccountNo,total.text);

And here is the cfinvoke for the same cfc.
&lt;cfinvoke component=&quot;wms05.orders.OrderForm&quot; method=&quot;getCarriage&quot; returnvariable=&quot;qryCarriage&quot;&gt;
&lt;cfinvokeargument name=&quot;DSN&quot; value=&quot;#request.productdsn#&quot;&gt;
&lt;cfinvokeargument name=&quot;AccountNo&quot; value=&quot;00027&quot;&gt;
&lt;cfinvokeargument name=&quot;OrderValue&quot; value=&quot;1000&quot;&gt;
&lt;/cfinvoke&gt;

I'm at a loss! Any help would be much appreciated.

Stephen
Stephen Moretti
Sorry for filling up the comments - I just got a response from Dave Watts on the CF-Talk mailing list that solved my problem and now that I see his description I realise now exactly what a couple of the notes were pertaining to.

Dave Watts pointed out that although I have a CF mapping to wms05 I probably didn't have a mapping in the webserver to wms05 for the direct call to the cfc by URL (which is what the &quot;connection.getService()&quot; function is actually doing.)

Laura
Stephen,
From the notes about remoting in the post:
&quot;The path to the component is the directory structure as viewed from the root of your website, separated by dots, followed by the component name.&quot;

That means the path has to be web accessible and also, the directory structure has to exist, either by real directories or by web server virtual directories. You must be able to browse to that folder and cfc. CF mappings are not enough, as the web server has no idea of their existence.
Tim
Great article. I am almost there--Im just missing the middle piece that connects it all.

In one CFFORM, I have a CFGRID that contains rows from a query. Then I have three textarea elements. When you click on a row in the grid, I want the textarea elements populated from the result of a method call to my CFC.

I think I understand the &quot;getData&quot; code, but how do I trigger the remote call when I click on a row in my cfgrid? The method I am calling expects an ID (which is one of my columns in the cfgrid).
Nahuel
Tim,
Cfform has an event on the grid that is called &quot;onchange&quot;. This gets executed everytime the user selects a row. You need to make the call to your cfc inside that event.
Muzak
61. Muzak wrote on October 04, 2005 at 5:51 PM
I was playing around with this a bit and found out that you can even debug the data transfer using the NetConnection Debugger (which comes with Flash Remoting if you have it installed).

Just add the following line at the top of the cfsavecontent block:

// enable NetDebugger
mx.remoting.debug.NetDebug.initialize();


Open the NetConnection Debugger before opening the .cfm page and watch the data displayed in the Debugger ;-)

regards,
Muzak
Nahuel
Cool, thanks for sharing :)
Mark
63. Mark wrote on October 10, 2005 at 1:54 PM
I am trying to pass a cfselect box over that has more then 1 value selected. Well when I pass it over only 1 value gets passed. I thought for sure it was because the comma so I did a replace right before I pass it and I still only get 1 value.

var responseHandler = {};

var Type = Type.value.split(&quot;,&quot;).join(&quot;|&quot;);

responseHandler.onResult = function( results: Object ):Void {
//when results are back, populate the cfgrid
searchResults.dataProvider = results;
}

responseHandler.onStatus = function( stat: Object ):Void {
//if there is any error, show an alert
alert(&quot;Error while calling cfc:&quot; + stat.description);
}

//get service
myService = connection.getService(&quot;ssLite&quot;, responseHandler );
//make call
myService.getSerchResults(Type);


&lt;cfselect enabled=&quot;Yes&quot; name=&quot;Type&quot; size=&quot;3&quot; label=&quot; Type:&quot; multiple=&quot;yes&quot;&gt;
&lt;option value=&quot;0&quot; SELECTED&gt;All Types&lt;/option&gt;
&lt;option value=&quot;typea&quot;&gt;A&lt;/option&gt;
&lt;option value=&quot;typeb&quot;&gt;B&lt;/option&gt;
&lt;option value=&quot;typec&quot;&gt;C&lt;/option&gt;
&lt;option value=&quot;typed&quot;&gt;D&lt;/option&gt;
&lt;/cfselect&gt;
Nolan Dubeau
Hello,

I am having some serious problems deploying my app to a live server and wonder if you could explain about the façade component with regards to Remoting. It appears that there are some comments on this issue, but I am at a loss to resolve. On my local machine the path to my components is www_mysite_com.com.concrete.somecomponent.cfc, and on the live server I created a CF mapping called www_mysite_com, and pointed it to the root directory of the site. Everything seems to be working correctly except for the Remoting calls. Any help is appreciated.
Matt
65. Matt wrote on October 24, 2005 at 10:37 PM
Nolan, you may want to ensure that your jrun and coldfusion are not clashing against the flashservices/gateway - see
http://www.talkingtree.com/blog/index.cfm?mode=entry&amp;entry=25AA89CA-45A6-2844-79F890861E204161

One issue I am having is applying a filter after calling the onClick=&quot;#getData#;applySomeOtherFilter()&quot;. The getData gets called, but the applySomeOtherFilter doesn't work. Without the #getData# call the filter does work. Any suggestions?
Laura
Nolan,
Flash remoting ignores CF mappings. The path has to be exactly your path from the root to the cfc, as if you were browsing it, just replace the slashes with dots. (Check the notes on remoting in the post) As a side note, you can have a virtual directory in IIS and that would be fine, because you can browse it, but not CF mappings.

Matt,
I think your problem is that you are calling the filter before the data gets back. You need to have your filter in the onResult or myFunction_Result function. These are asynchronous calls, so the data is not available as soon as you make the function, and there is no guarantee about when it will arrive.
Matt
67. Matt wrote on October 25, 2005 at 1:30 AM
Thanks Laura. I moved the filter into the onResult function. What happens is that after the following line:
clientGrid.dataProvider = results; // where results have 7 records

clientGrid.dataProvider.length is equal to 7
However, I am not able to iterate over the newly populated data grid for some reason. ie clientGrid.dataProvider[1][&quot;columnname&quot;] is empty.
Any suggestions?
Laura
Matt,
For your example to work, you need to set the dataProvider as:
clientGrid.dataProvider = results.items;
Mike
69. Mike wrote on November 10, 2005 at 10:33 AM
Laura,

I want to return just one row of a query from a cfc. But I can't figure out the correct way to get it from the cfc back to the cfm. It always comes up as undefined. If I go from returntype=&quot;string&quot; I get a different error. Any help would be appreciated.

Mike
Laura
Mike,
If you are sending the query directly, then access the first (and only) item by:
var item:Object = results.getItemAt(0);
then item is a structure with columns as keys.
item.myColumn
Mike
71. Mike wrote on November 15, 2005 at 3:45 PM
Laura,

Thanks alot, that worked well.

Mike
colin
72. colin wrote on November 17, 2005 at 1:02 PM
Hi there,

I am trying to display the data returned from a cfdirectory query, for some reason i get the headers back, but not the actual data list.
any reason that you may know of ? Everything works fine if i use an actual db query name.

Thanks in advance :)

NetConnectDebugInfo:
--------------------------
Result (object #2)
.....mRecordsAvailable: 0
.....serverInfo: (undefined)
.....uniqueID: 0
....._items (object #3)
..........No properties
.....mTitles (object #4)
..........[0]: &quot;Name&quot;
..........[1]: &quot;Size&quot;
..........[2]: &quot;Type&quot;
..........[3]: &quot;DateLastModified&quot;
..........[4]: &quot;Attributes&quot;
..........[5]: &quot;Mode&quot;
..........[6]: &quot;Directory&quot;

Ken
73. Ken wrote on November 24, 2005 at 6:53 PM
I have the following situation.
I need to check if a value entered into a text box already exists in the db.

No problem there I have modified your great example of flash remoting to do this.
But if the value is found, I would like to display to the user an alert message (plus disable the submit button, which I have done)

But I have also used your alert example and the problem I encounter is that it just hangs until a message come back saying that the script is causing the player to run slowly.

Can you shed some light on this problem ?
I should also say that if I don't use your alert example and just use
alert('my alert text');
it works, but as the form is long the alert message is not displayed on the screen, the user has to scroll down to it. I have also not been able to &quot;move&quot; this alert.
Ken
74. Ken wrote on November 26, 2005 at 2:42 AM
An update of my lost post

I have found that the problem with this is the scope setting of &quot;this&quot;, if I change this to &quot;_root&quot; it all works as expected. But of cause the alert box will not close. I have tried replicating the deletePopup() code from flash but no luck as yet.

Ken
Philippe Maegerman (Pim)
I have noticed that sometimes using _level0 instead of _root solved my problems ...
Ken
76. Ken wrote on November 26, 2005 at 3:59 PM
I have tried this, _root, _level0

But it's most probably where I have to put it is the problem.
Here is my code

responseHandler.onResult = function( results: Object ):Void {
//when results are back, we show the text received
display.text = results;

var alertSettings:Object = {closeButton:true, title:'Warning', message: &quot;My Message&quot;, width:350, x: 60, y: 10, headerHeight: 27};

var myTW = mx.managers.PopUpManager.createPopUp(_root, FormErrorException, true, alertSettings);

var windowListener = {};
windowListener.click = function(){
_root.myTW.deletePopUp();
}
myTW.addEventListener(&quot;click&quot;, windowListener);}

I have tried a number of combinations all with no result.
Ken
77. Ken wrote on November 26, 2005 at 7:45 PM
As I said, just putting the _root in the wrong place.

Heres the code that works

var msg = 'A simple alert with position x:60, y:10';
var alertSettings:Object = {title:'Off center', message: msg, headerHeight:27, x: 60, y: 10};
_root.errorpopup = mx.managers.PopUpManager.createPopUp(_root, FormErrorException, true, alertSettings);

Ken
Laura
Ken,
I am glad you got it working.
However, as I said the post http://www.asfusion.com/blog/entry/customizing-a-cfform-alert-with-pictures-and
I would strongly recommend *against* using the errorpopup variable. It depends too much on current cfform implementation code. If you use it, you must be willing to accept that your code may break in future CF releases.
Ken
79. Ken wrote on November 26, 2005 at 8:36 PM
Laura,
Thanks for the response. Yes, I did read your comments in your example and yes I do agree.
But as the form I have is long (I have no option here, clients !!), I have to resolve the alerts being displayed in a position that you have to scroll down to them. If I could find a way to move the normal &quot;alert&quot; then I would use them.

Just have to be aware that the code may break.

Ken
Nelly
80. Nelly wrote on December 31, 2005 at 7:39 AM
I get this error when I click Get Date:

&quot;Error while calling cfc: Service threw an exception during method invocation:null&quot;

Is there something wrong with my Flash Remoting configuration? I am using ColdFusion MX 7.0.1 (merged with Flex). Both files are in my root folder and the server name is cfusion.local (for development use). So I set the connection and get service values as follows:

var connection:mx.remoting.Connection = mx.remoting.NetServices.createGatewayConnection(&quot;http://cfusion.local/flashservices/gateway/&quot;);

myService = connection.getService(&quot;flashRemotingResponder&quot;, responseHandler );

Can anyone tell me what the source of the error is?
REB
81. REB wrote on January 13, 2006 at 8:18 AM
Laura,

Thank you for explaining remoting! This has helped me to understand the requirements for returning results. Thanks!

-Richard
MJE
82. MJE wrote on March 02, 2006 at 3:57 PM
Hi,

I am hoping that this example can solve my woes. I'm losing it over here! Here is the issue - I need to be able to filter an item in a select list based on an item that is selected in a datagrid (which in turn binds three of the grid fields to text boxes).

In my mind, the easiest way to do this would be to have a query that basically says select * from table where value=&quot;{mydata.text}&quot; - of course, that would be in a perfect world, and I have not, for the life of me, been able to figure out how to query using cf.query or cfscript, or this example, so that I can filter the select box based on either the item selected in the data grid, or the text box that it is bound to.

Here is what I am working with so far - the job guide section below is what needs to be made dynamic based on the publication chosen:

&lt;cfgrid name=&quot;grid&quot; query=&quot;getPublications&quot; selectmode=&quot;single&quot; rowHeaders=&quot;false&quot; height=&quot;100&quot; tooltip=&quot;Choose a source reference from the list below&quot;&gt;
      &lt;cfgridcolumn name=&quot;publication&quot; width=&quot;300&quot; header=&quot;Source Reference&quot; &gt;
      &lt;cfgridcolumn name=&quot;pubDate&quot; header=&quot;Pub Date&quot; display=&quot;false&quot; mask=&quot;MM/DD/YY&quot;&gt;
      &lt;cfgridcolumn name=&quot;changeTitle&quot; width=&quot;75&quot; header=&quot;Change Title&quot; display=&quot;false&quot; &gt;
      &lt;cfgridcolumn name=&quot;changeDate&quot; header=&quot;Change Date&quot; display=&quot;false&quot; mask=&quot;MM/DD/YY&quot;&gt;
   &lt;/cfgrid&gt;
&lt;/cfformgroup&gt;   
       &lt;cfformgroup type=&quot;Horizontal&quot; label=&quot;Publication:&quot;&gt;
           &lt;cfinput tooltip=&quot;Choose a publication/source reference from the list above&quot; type=&quot;text&quot; name=&quot;taskPublication&quot; bind=&quot;{grid.selectedItem.publication}&quot;
    required=&quot;no&quot; message=&quot;Please select a task publication&quot; editable=&quot;false&quot;&gt;
       &lt;/cfformgroup&gt;
       &lt;!--- pub date, change title and change date ---&gt;
&lt;cfformgroup type=&quot;HBox&quot;&gt;
&lt;cfformgroup type=&quot;VBox&quot;&gt;
&lt;cfinput type=&quot;text&quot; name=&quot;pubDate&quot; label=&quot;Pub Date:&quot; bind=&quot;{grid.selectedItem.pubDate}&quot; editable=&quot;false&quot;&gt;
&lt;/cfformgroup&gt;
               &lt;cfformgroup type=&quot;VBox&quot;&gt;
&lt;cfinput type=&quot;text&quot; name=&quot;changeTitle&quot; label=&quot;Change Title:&quot;bind=&quot;{grid.selectedItem.changeTitle}&quot; editable=&quot;false&quot;&gt;
&lt;/cfformgroup&gt;
&lt;cfformgroup type=&quot;VBox&quot;&gt;
&lt;cfinput type=&quot;text&quot; name=&quot;changeDate&quot; label=&quot;Change Date:&quot;bind=&quot;{grid.selectedItem.changeDate}&quot; editable=&quot;false&quot;&gt;
&lt;/cfformgroup&gt;
&lt;/cfformgroup&gt;
            
      &lt;!--- job guide - THIS IS THE AREA that needs to be filtered by publication selected - all I need to be able to do is figure out how to get the taskPublication field, or the publication field selected in the grid to be used as a variable to filter the job guide - Please help! ---&gt;
&lt;cfformgroup type=&quot;HBox&quot;&gt;
&lt;cfformgroup type=&quot;VBox&quot;&gt;
&lt;cfselect name=&quot;jobGuide&quot; label=&quot;Job Guide No:&quot;&gt;
      &lt;option value=&quot;&quot;&gt;Select a job guide&lt;/option&gt;
&lt;cfoutput query=&quot;getJobGuides&quot;&gt;
&lt;option value=&quot;#jobGuide#&quot;&gt;#jobGuide#&lt;/option&gt;
&lt;/cfoutput&gt;
&lt;/cfselect&gt;
          &lt;/cfformgroup&gt;
MJE
83. MJE wrote on March 02, 2006 at 4:52 PM
OK, I got the select able to populate using the flash remoting for cfselect example - thanks!!

Now, I'm getting the same issues with the binding mentioned earlier, but the posted resolve did not work for me. All I did was copy and paste the code that worked into my test page with the cfselect. This is the final missing piece - is there another 'foolproof' binding format that I can use?
MJE
84. MJE wrote on March 02, 2006 at 8:54 PM
Sorry again to take up the space - stupid me - in my haste I did a select * from table and the first letter by default was a capital letter, which I wasn't specifying. All is well - thanks so much for posting all of this information to the site - this is one of my most invaluable resources while developing with flash forms!
Don
85. Don wrote on March 14, 2006 at 2:40 AM
I still dont get it, it works in the root directory but no wher else, I dont understand where to edit the path.CFC. I dont understand your examples if none of the text matches up where I can find it in the source
Ed
86. Ed wrote on March 21, 2006 at 2:25 PM
I must say this is the kewlest thing! I was trying to do the same thing with all kinds of hacks and found this post. This solution is awesome! It does exactly what I needed to do. Any thoughts on performance impacts? Like what will remoting act like if there are hundreds/thousands of users?
Laura, you are the MA... er,well you ROCK! Thanks so much for the post!
David
Are the /flashservices/gateway directories actual physical directories? Or is that just a placeholder value in the opening of the &lt;cfsavecontent&gt; tag? The directories are nowhere to be found on my machine--which is running CFMX 7.

Was there an option to install the flash service during CF installation that I could have deselected?
Laura
David,
/flashservices/gateway are not actual directories. They are a servlet mapping defined in the web.xml file and it is installed by default. In previous versions, you could see a blank screen if you browsed directly, but that is not the case anymore, the simplest way to make sure you have it properly installed is to run the code and see if it works :)
daniel fredereicks
Ok, so i read that flash remoting takes the place of outside swf files...
What if I am trying to insert a swf file into say an accordion? I can get it to display using the &lt;img&gt; tag, but, i am also using flash remoting, which for some reason does not seem to bring bacm my data and display.
Is there any conflict between cf flash forms and the swf?

I really need to find this answer.

dan
Tom
90. Tom wrote on April 15, 2006 at 9:56 PM
I get a error message...EVERY time I try to run a search.


&quot;Element USERNAME is undefined in VARIABLES&quot;
Daniel Fredericks
91. Daniel Fredericks wrote on April 28, 2006 at 7:17 AM
NetConnection Debugger...how do you open it to view your CF pages? isn't the debugger within flash?

Help me on this....
Gerald
92. Gerald wrote on May 12, 2006 at 9:34 AM
Nice. How would one submit and process the contents of a grid (multiple rows possibly) via flash remoting? If the answer is not simple, direction to any resources will be appreciated. Thanks much!
Brian
93. Brian wrote on May 13, 2006 at 4:43 PM
I donwloaded the two source available above and tried them out on my server but I'm wondering why I'm getting this error: "error while calling cfc: service, flashRomotingResponder not found" I'm obviously new to flash remoting but very excited about it.

Checklist:
-Coldfusion mx 7
-I see the flash form and form elements
-Click on "Get Data"
-Then error is called with flash pop-up.

Thanks, Brian
Laura
daniel,
It is very difficult to say what exactly your problem with the swf is. It should work fine, but remember there will be no communication between the form and your swf unless you program it to do so.

Tom,
That means you have an error in your cfc.

Gerald,
You could loop over the records of your datagrid and create an array with the data you need or if you loaded the grid normally (not manually via remoting), you could send the dataprovider directly and receive it as an array in CF.

Brian,
The example assumes you have your file in the root of your site (http://www.example.com/simple-remoting.cfm ) If that is not your path, then you need to change it in the line that calls the service (getService())
Rey
95. Rey wrote on June 21, 2006 at 12:21 PM
I'm trying to use flash remoting to insert data into a database but it's not working, here is my savecontent tag:
<cfsavecontent variable="checkValues">
      if (emp_NAMEa.text == '')
      {
      mx.controls.Alert.show('Employee Name is required!');
      }
      else if (FTa.text == '')
      {
      mx.controls.Alert.show('Employee Status is required!');
      }
      else if (TITLEa.text == '')
      {
      mx.controls.Alert.show('Employee Title is required!');
      }
      else if (DM_NAMEa.text == '')
      {
      mx.controls.Alert.show('District Manager Name is required!');
      }
    else if (DOHa.text == '')
      {
      mx.controls.Alert.show('Date of Hire is required!');
      }
      else if (SVC_MGR_NAMEa.text == '')
      {
      mx.controls.Alert.show('Service Manager Name is required!');
      }
      else
      {
      //create connection, replacing the gateway url with yours
var connection:mx.remoting.Connection = mx.remoting.NetServices.createGatewayConnection("http://localhost/flashservices/gateway/";);
   
//declare service
var myService:mx.remoting.NetServiceProxy;
//put the controls in scope to avoid calling _root
    var emp_NAMEa = emp_NAMEa.text;
    var FTa = FTa.text;
    var TITLEa = TITLEa.text;
    var DM_NAMEa = DM_NAMEa.text;
    var DOHa = DOHa.text;
    var SVC_MGR_NAMEa = SVC_MGR_NAMEa.text;
   
    //make an object that will handle the response
var responseHandler = {};
   
    //function that receives the response
responseHandler.onResult = function( results: Object ):Void {
//when results are back, we show the text received
var msg = results;
}
    //function that receives any error that may have occurred during the call
responseHandler.onStatus = function( stat: Object ):Void {
//if there is any error, show an alert
alert("Error while calling cfc:" + stat.description);
}
    myService = connection.getService("cfc.add_emp", responseHandler );
//make call, passing one parameter
myService.addEmp(emp_NAMEa.text,FTa.text,TITLEa.text,DM_NAMEa.text,DOHa.text,SVC_MGR_NAMEa.text);
      }
   </cfsavecontent>
and here is my cfc:
<cfcomponent>
   <cffunction name="addEmp" access="remote" returntype="string">
    <cfargument name="TITLEa" type="string" required="false" default="">
    <cfargument name="emp_NAMEa" type="string" required="false" default="">
    <cfargument name="FTa" type="string" required="false" default="">
    <cfargument name="DOHa" type="string" required="false" default="">
    <cfargument name="DM_Namea" type="string" required="false" default="">
    <cfargument name="SVC_MGR_NAMEa" type="string" required="false" default="">
       <!---Add employee--->
<cfswitch expression="#form.TITLEa#">
<cfcase value="Bio Sys Service Supervisor">
<cfset TechCode = "Sup">
</cfcase>
<cfcase value="Bio Sys Service Manager">
<cfset TechCode = "Man">
</cfcase>
<cfcase value="Bio Sys Service Specialist">
<cfset TechCode = "Tech">
</cfcase>
<cfcase value="Bio Sys District Manager">
<cfset TechCode = "DM">
</cfcase>
</cfswitch>
<cfquery datasource="stcycle">
INSERT INTO dbo.payroll (TechCode, emp_NAME, FT, DOH, TITLE, DM_Name, SVC_MGR_NAME) VALUES ('#form.emp_Namea#','#form.FTa#','#form.DOHa#','#form.TITLEa#','#form.DM_Namea#','#form.SVC_MGR_NAMEa#','#TechCode#')
</cfquery>
<cfset msg = 3>
      <cfreturn msg>
   </cffunction>
</cfcomponent>
Any thoughs as to why it's not working correctly, meaning it's not inserting the values passed by the form into the database, I have been at this for 2 days now, Please Help!!!
Ed
96. Ed wrote on June 21, 2006 at 12:40 PM
Hi Rey,
Providing you are not getting an error...
Try removing the form. in front of your cold fusion variables in the insert statement... Remoting does not use the form scope. For example try this:

INSERT INTO dbo.payroll (TechCode, emp_NAME, FT, DOH, TITLE, DM_Name, SVC_MGR_NAME) VALUES ('#emp_Namea#','#FTa#','#DOHa#','#TITLEa#','#DM_Namea#','#SVC_MGR_NAMEa#','#TechCode#')

Also, remove the .text in the call below...
myService.addEmp(emp_NAMEa.text,FTa.text,TITLEa.text,DM_NAMEa.text,DOHa.text,SVC_MGR_NAMEa.text)

You are referencing the variable that already holds the text in the variable calls above...

Also..
In your insert call your variables appear to be out of order. Try putting '#TechCode#' in the beginning of the values call to match the column name list.

If you are getting a remoting error... Let me know.
Hope this helps!

Ed
Rey
97. Rey wrote on June 22, 2006 at 4:42 AM
nope nothing works, for some reason I don't even get errors even after applying the changes you recomended, I click the button and nothing happens. I really don't un