| Register
Saturday, May 17, 2008   

Consuming Web Services and Flash Remoting

Created By  Chris Bizzell, at  12/10/2004 - 9 comments.

Click to view this author's website.

This article will look at another technique for consuming a public web service via Flash Remoting.

Why Flash Remoting?

If you have worked long enough integrating public web services into your Flash apps, inevitably you have come across a service that works great when you test your application inside the Flash IDE but fails to work through a browser. This is a result of the Flash Security Sandbox. Macromedia describes this sandbox thusly:

Access to external data through any connector component is subject to the sandbox security model in Flash Player, for all Flash applications that run in a web browser. The sandbox security model restricts a Flash document from accessing data from any domain other than the one in which it originated (this includes public web services).

This restriction can be overridden through the use of a cross domain policy file on the service originator's server - Read More.

Flash Remoting enables you to bypass the security sandbox issue and utilize remote data from web services by creating a proxy for your remote service locally. Actionscript 2.0 introduces several changes to the syntax used to consume web services with remoting. The following utilizes several new Classes needed when working with web services and Flash Remoting:

import mx.remoting.PendingCall

import mx.remoting.RecordSet

import mx.remoting.Service

import mx.rpc.RelayResponder

import mx.rpc.ResultEvent

import mx.rpc.FaultEvent


This example will use the state names and abbreviations web service that we used in my last article. The service is located HERE.

Open Flash and create a new Flash File.

The first thing we need to do is drag an instance of the datagrid onto the stage and delete it. This makes the datagrid available in our Library. Second, drag the Remoting and Web Service Classes onto the stage and delete them as well. To do this go to Window >> Other Panels >> Common Libraries >> Classes. There you will see the Web Service and Remoting Classes. Now our Classes are available to be called via our Actionscript when needed.

Select Frame one of layer one and attach the following code (Cut and Paste Code):


The code is commented so I won't go into more discussion however, I will point out the change in the syntax for setting the dataprovider from our earlier example.

With Remoting the datagrid is populated by looking at the regionitem array passed from the service:

myDataGrid.dataProvider = re.result.list.regionitem;

Whereas the Web Service Classes method set the dataProvider as so:

myGrid.dataProvider = result.list;

This was not readily apparent at first and I thank Paul Newman for helping me out with the solution.

I hope this example will shed more light on another set of powerful tools that you can use when you develop your Flash applications.

Need Professional Help For Your ActionScript Project?
ActionScript.com Consulting Services provide top quality professional ActionScript consulting to businesses around the globe. If you have a professional project in need to world-class talent, tell us about your project by requesting a quote today.

Reader Comments

  1. Dave_Matthews  Replied:
    ( 1/15/2005 At 7:08 PM)

    Can't seem to copy (/paste) the code block, it's a .gif... :)

  2. cvb  Replied:
    ( 1/15/2005 At 8:17 PM)

    there is a link in the body of the article that takes you to the cut and paste code

  3. Brian Manning  Replied:
    ( 1/19/2005 At 12:34 AM)

    I was looking for the remoting classes the way you specified and they dont show up
    is there some place I can down load the complonets or classes from

  4. up0  Replied:
    ( 1/19/2005 At 1:59 AM)

    Don't forget to setup the Flash Remoting on the server side! A good alternative to Flash Remoting is a free AMFPHP (http://www.amfphp.org/). Use it to setup a gateway and you should be able to access any web service, etc.


    up0.com

  5. Andrew  Replied:
    ( 1/19/2005 At 1:35 PM)

    I have installed flash Remoting 2.0 components but when I test it doesn't import the classes. Have searched for them and they don't seem to have been installed. Any clues?

  6. cvb  Replied:
    ( 1/21/2005 At 5:32 AM)

    Excerpted from the last article:
    The last thing you need to do for our example to work is to import the Web Service Classes into Flash. To do this go to Window >> Other Panels >> Common Libraries >> Classes. There you will see the Web Service classes. Drag an instance onto the stage and delete the instance. The Classes you need are now in the library ready to be called by Flash at runtime.
    Hope that helps -

  7. Bertil Gralvik  Replied:
    ( 3/8/2005 At 2:40 AM)

    Hi!
    And esp. Dave Matthews.
    That *was* funny indeed - I too was convined to copy and paste that visible code!
    Thanks Dave, I'm not alone in going for the obvious :-)
    /Bertil

  8. C Anderson  Replied:
    ( 7/21/2005 At 7:52 AM)

    I have included the Web Service classes in my fla library as indicated in item 6 above. I still get the error:
    "The class 'mx.rpc.RelayResponder' could not be loaded."
    I am using remoting connector components elsewhere in my flash app.
    Any ideas?
    Thanks.

  9. Ski  Replied:
    ( 12/5/2005 At 2:58 AM)

    Have you installed
    Macromedia Flash Remoting Components for Flash MX 2004 ActionScript 2.0
    from
    http://www.macromedia.com/software/flashremoting/downloads/components/#flr_as2
    ?

Login to post your comments. If you do not have an account with us please Register.
Copyright 2005 by ActionScript, Inc.   |  Privacy Statement  |  Terms Of Use  |  ActionScript Client Extranet