Our Blog

One of the lesser-known features of the Flash Remoting gateway is to act as a proxy to a web service. Using this proxy, you can effectively circumvent the cross-domain restrictions in the flash player, as all calls are local to the flash movie.

It turns out to be very easy to make the call. It is almost exactly the same as calling a local CFC

What changes is that instead of setting our service to "myPath.to.cfc", we set it to the actual web service address:

myService = connection.getService(
"http://weblogs.macromedia.com/mxna/webservices/mxna2.cfc?wsdl", responseHandler );

and then call the desired function:

myService.getMostRecentPosts(50,0,1);

I am using the MXNA Web Service (http://weblogs.macromedia.com/mxna/webservices/mxna2.cfc?wsdl) as an example.

The tricky part is that the Web Service Proxy is not enabled by default in ColdFusion’s Remoting gateway. To enable it, open the gateway-config.xml file in C:\CFusionMX7\wwwroot\WEB-INF (or similar path) and uncomment

<adapter>coldfusion.flash.adapter.CFWSAdapter</adapter>

inside the node near the top. Then restart ColdFusion.

View live example
Download the source

Laura

Laura

19 Comments

  1. Asher Gilbert
    Recently, ASFusion has posted some excellent articles on the use of the Flex components on CF MX.
    I've just finished building this photo album application using the remoting features and upload features recently explained on this blog. Thanks alot guys. Top Draw!
    &lt;br&gt;
    &lt;a href=&quot;http://varian.zealio.com/screenshots/photoAlbum.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://varian.zealio.com/screenshots/photoAlbum-thumb.jpg&quot; width=&quot;210&quot; height=&quot;166&quot; border=&quot;0&quot;&gt;&lt;/a&gt;
  2. Michael

    Michael

    Just wanted to say YOU PEOPLE ROCK! Flash forms were useless before you, now they are important tools. Now, for my question. With the new enhancements to CF forms in 7.01, what would be a good reference book to pick up to help me with flash forms and actionscript.

    I have used most of the examples on the site to create rich interactive forms, but want to move furthur and hoped you could push me in the right direction.

    Thanks in advance
  3. Hi Michel
    We have a small list with some great books.
    http://www.asfusion.com/bookmarks/category/flash-books
  4. veejay
    Is there any way of consuming WebServices without remoting?? I need it thru ActionScript. Any code will help.

  5. Laura
    veejay,
    Do you want to do that in a cfform? If so, no, it is not possible.
    If you want to do it in Flash (not cfform) check the Flash documentation for the Web Service component.
  6. Douglas Knudsen

    Douglas Knudsen

    I'm really late to this whole conversation, but has anyone got this working on a HostMySite account? I got them to setup the flash remoting gateway thingy, but I keep getting a HTTP BASIC AUTH security popup wanting a user name and password. ????
  7. Douglas Knudsen

    Douglas Knudsen

    ok...got it working. The fine folks at HostMySite hooked it up!
  8. John Barrett
    Thanks you so much`-`!
    Laura, thanks so much for this, I am reading this, and I got it to work on my Mac, and I am actully starting to understand`-`

    I am so stoked a local way of checking the lastest blogs, and with flash forms WOW!! It is a beautiful application`-`

    One question?
    What happen to the link to buy you something? Am I blind, or did you take the amazon wish list off??

    Thanks again!`-`
    John
  9. Lesley
    I am trying to understand flash remoting, but I can't seem to get it to work.

    I am getting the error Element COMPONENTPATH is undefined in REQUEST.

    Here is the code that is in question:
    Public function setUpRemoting(): Void{
          <cfoutput>
          var connection:mx.remoting.Connection = mx.remoting.NetServices.createGatewayConnection("http://#cgi.HTTP_HOST#/flashservices/gateway/");
          var componentPath = MHC.services.ListingService";
          var componentPath:String = "#request.componentPath#.services.ListingService";
          </cfoutput>

    Can anyone help me debugg this?
  10. Laura
    Lesley,
    Remove this variable and replace it with your particular path, whatever it is.
    var componentPath:String = "#request.componentPath#.services.ListingService";

    to something like:
    var componentPath:String = "THE.PATH.TO.YOUR.CFC";
  11. Laura
    Actually, you already wrote it, but left the old code there. Remove var componentPath:String = "#request.componentPath#.services.ListingService";
  12. Lesley
    Thanks! That fixed one problem and now I have 5 more. How do you figure out these errors when they don't tell you where they are?

    Here are the error messages:
    5 Errors found.

    Error /MHC/Test-.mxml:1147
    ';' expected


    Error /MHC/Test-.mxml:1147
    The statement 'Public' is incomplete.


    Error /MHC/Test-.mxml:1221
    Attribute used outside class.


    Error /MHC/Test-.mxml:1235
    Attribute used outside class.


    Error /MHC/Test-.mxml:1273
    Unexpected '>' encountered
  13. Lesley
    I really need help. I tried to fix it my self and now I have 22 errors. Would anyone be willing to view my code and let me know what I am doing wrong? Let me know
  14. Tim
    Hi all,
    I have recently found an issue that i need some help understanding.

    I have a CFForm that calls my CFC on load and fills a data grid.

    Most of the time it works fine but once in a while i can see it fill the grid on load then simply disapear.

    Any idea what can cause this?

    Here is my function that calls my cfc and fills the grid:
    <code>
    function setAttendance(UID):Void{
    <cfoutput>#conn#</cfoutput>
    var vacgrid = vacgrid;
    var pergrid = pergrid;
    var sickgrid = sickgrid;
    var uatService:mx.remoting.NetServiceProxy;
    var uatHandler = {};uatHandler.onResult = function(uatresults:Object):Void {

    vacgrid.dataProvider = uatresults.VAC; pergrid.dataProvider = uatresults.PER; sickgrid.dataProvider = uatresults.SIC;}
    uatHandler.onStatus = function(stat:Object):Void {alert("Error while gettiing Attendance Values:" + stat.description);}
    uatService = connection.getService("CFC.users", uatHandler);
    uatService.HR_attendance(UID);


    }


    <cfgrid name="vacgrid" rowheaders="false" height="130">   
    <cfgridcolumn name="name" header=""/>
    <cfgridcolumn name="days" header="Days"/>   
    <cfgridcolumn name="hours" header="Hours"/>
    </cfgrid>
    <code>

    thanks in advance

    tim
  15. Laura
    Tim,
    See this post:
    http://www.asfusion.com/blog/entry/knowing-when-the-cfform-data-arrives
  16. Tim
    hi Laura,
    Thanks for the quick post, i can resolve this by the following:
    remove the remoting and call the cfc through cfscript and assign the result the query tag of the grid.

    I seem to have this issue anytime i try to load data in the onload of a form. in the past i just used a button to load the data.

    I will read through the link you posted for some pointers though, thanks again

    p.s. congrats on your cert!
    was the test difficult?
    tim
  17. Jim
    Has anyone consumed a web service using Flash Remoting over SSL? If so, any code samples woiuld be appreciated, especially on how to pull in the SSL certificate and include it in the request to the web service host. If not, any ideas on how it could be done? Thanks much, and at the risk of repeating the thoughts of others, "this site rocks!"
  18. nsr
    Hi,

    I'm getting following error:
    Service threw an exception during method invocation: No service named fileexplorer.services.fileExplorer is known to Flash Remoting.

    Note: I have enabled flash remoting by uncommenting <adapter>coldfusion.flash.adapter.CFWSAdapter</adapter>