Tutorial: BabelFish with WebServiceConnector

The new WebServiceConnector component in Flash MX 2004 Professional makes talking to standard (SOAP) web services extremely easy. Here’s how to make a simple call to the BabelFish web service using Flash MX 2004 Professional’s new features:

  1. Drag the WebServiceConnector component to the stage (just outside of it), and give it an instance name “babelfish”
  2. Select it and open the Component Inspector
  3. Under the Parameters tab, enter the WSDLURL:
    http://www.xmethods.net/sd/2001/BabelFishService.wsdl
  4. Click the next field “operation” and select BabelFish
  5. Click the Schema tab and check out the schema for this web service
  6. Note that it requires two parameters (translationmode and sourcedata), and it returns a string
  7. Now let’s create the interface of the application:

  8. Drag a TextInput component to the stage, adjust its size as needed, and give it an instance name “sourcedata”
  9. Drag a ComboBox to the stage and name it “translationmode”
  10. Drag a TextArea component to the stage (this is for displaying the result from the web service), adjust its size as needed, and name it “results”
  11. Drag a button to the stage, change its label to “Translate”
  12. With the button selected, add a new behavior from the Behaviors panel: Click the + button, select Data – Trigger Data Source. In the popup window, select babelfish.
  13. Let’s bind the babelfish component to the interface:

  14. Select the babelfish component, open the Component Inspector panel and click the Bindings tab
  15. Click the + button, select “translationmode:string”, and click OK. Double-click on the “bound to” field underneath. In the Bound To dialog box, select “Combobox, ” on the left, and “value:String” on the right. Click OK.
  16. Add another binding, this time select “sourcedata:String” and click OK. In the Bound To dialog box, choose “TextInput, ” and click OK.
  17. Add another binding, select “results:String” and click OK. In the Bound To dialog box, choose “TextArea, ” and click OK.

Now is a good time to save the FLA.

Before we can make this work, we need to populate the ComboBox. First, let’s take a look at how the web interface of BabelFish looks like: http://babelfish.altavista.com/. From the dropdown menus, you can tell the languages and translation directions.

View Source from the browser, inspect the data that is sent to the server when an item is selected from the dropdown menu:

Let’s populate these data into our ComboBox: Deselect all items from the stage, and add a new script:

That’s it! Test movie and enter some text, select a translation mode, and click the Translate button to see the translated text! Not too bad is it? Try it out:

Okay, this is what it looks like. Why doesn’t it work? It’s because when the new Flash Player 7 is running inside a browser through HTTP, the new cross-domain security prevents this SWF from loading data from another domain.

What is needed is a policy file – an XML document specifying who is allowed, and this file has to reside at the web service domain. One way to get around this is to use a redirection proxy (server-side script) at this domain, to pass the data between servers and back to this translator. This will be the subject for another day.

UPDATE:

Instead of hardcoding the translation modes into the movie, Mark Shepherd of Macromedia suggested using the XMLConnector component to load an external XML file with the translation modes, and bind the data to the ComboBox. I’ve gone one step further by adding the web service URL in this XML document (BabelFish.xml). This is what I usually do for application configurations, it makes updating quick and easy without going into the source movie and recompiling another SWF.

Also, a redirection proxy file is being used. However, for some reason, this proxy only works when the movie is running inside Flash’s IDE or from the desktop standalone projector, but still not from this domain, even though both the SWF and the proxy are located in the same folder. This is the proxy similar to the one posted at Macromedia, except I’m using JScript instead of VBScript (that does not work either):

Why does this proxy work outside of the browser and not from the same domain? I’d really like to get an answer to this one.

You can download the source files, check them out and let me know if you find anything. Thanks!

12 thoughts on “Tutorial: BabelFish with WebServiceConnector

  1. What is needed is a policy file – an XML document specifying who is allowed, and this file has to reside at the web service domain.

    ahem no, refering to the FMX2K4 documention,
    the policy file need to reside at the server root containing the SWF

  2. Sorry, but that is incorrect.

    “Policy files must be named crossdomain.xml and reside at the root directory of the server that is serving the data.”

    That is the server hosting the web service, not the SWF. Otherwise what is the point of enforcing this security if anyone can place a policy file at their own domain with their SWFs?

  3. ok you’re sorry I’m sorry,
    we’re both sorry, but considering this:
    —-
    “Policy files must be named crossdomain.xml and reside at the root directory of the server that is serving the data.”
    —-

    you can read it 2 way:

    – either the crossdomain.xml is in the root directory for the server hosting SWF, the one requesting the external data

    – or the crossdomain.xml is at every server root directory providing web services

    the second way is totally ridiculous,
    can you seriously imagine that every server providing web services will provide this xml for every other external web site requesting the web services ?

    now applying the KISS principle,
    is it more simple to have the xml for the SWF which will set the connection to few external webservices

    or

    is it more simple to have web services provider like babelfish including a xml file at their root directory for every external web site willing to use their webservices ?

    —-
    That is the server hosting the web service, not the SWF. Otherwise what is the point of enforcing this security if anyone can place a policy file at their own domain with their SWFs?
    —-

    the point here is that the crossdomain.xml enforce the security of the SWF, not the security of the web services.

    this is not personnal, just my 0.2 euros logic
    wish you the best for your blog

  4. I implemented my own webserives implemented using websphere studio.

    when i tried to access using flash webservice connected component..after drag and drop the connecter component and in the parameter tab when i enter the wsdl file. it gives me the old operatiion in the wsdl. but i changed some of the operation in the source still it giving the old services.how to delete the catch and get the latest services form the wsdl file pl find me a solution ..thanks in advance anand

  5. and inferences based on how they’re dressed, direcway etc., but those are only generalizations at best, free satellite tv and stereotypes at worst). The downsides are free dish network legion, of course. First of all, I’m just not direct tv inclined to talk to strangers in the first place. free directv Having something like this where it’s a weird free direct tv kind of talking to strangers makes it even more satellite tv difficult. There is a very real possibility of dish network coming off as deranged, after all. Also – this directv

  6. Hi,
    I did your translation example tonight & it worked like a charm, no policy file/XML document needed. I tested with various words that I knew in various languages (I like different languages, which I know from songs) – worked very well. Using Flash MX 2004 Pro (Educ. Vers.), and Win. XP Pro. Thanks very much for the tutorial.

  7. Is there any way to ensure all the special characters returned (for spanish for instance), won’t show up as little squares?

Leave a Reply

Your email address will not be published. Required fields are marked *

3 × two =