Community Documentation

Example: Accessing a service from Flash 8

Last updated April 6, 2010. Created by texas-bronius on May 2, 2007.
Edited by heyrocker. Log in to edit this page.

Accessing exposed services from Flash8 Professional is easy, but some basic setup is required. Below the setup is sample code scraped right out of a thread in the Services group with one minor modification: I added a bit more to getData_Result to dump the retrieved node.title and node.body as well as peppered with comments for the less-adventurous.

  1. Install and configure Services in Drupal. Note: I found that I had to enable Access Services to anonymous users in Admin>>UserMgmt>>Access Control. In Services config, I also turned off API key and Session Key.
  2. Download and install the required Flash Remoting components:
    http://www.adobe.com/products/flashremoting/downloads/components/
  3. Launch Flash 8, create a new movie, open the newly installed libraries: Click Window>>CommonLibraries>>Remoting. Drag both components onto the stage (which adds them to the movie's library) and delete from the stage.
  4. Put the following actionscript code in frame 1 of your flash movie:
    // Picking up a Drupal node with flash remoting
    // Drupal must be set up with Services module enabled
    import mx.remoting.Service;
    import mx.remoting.PendingCall;
    import mx.rpc.RelayResponder;
    import mx.rpc.FaultEvent;
    import mx.rpc.ResultEvent;
    import mx.remoting.debug.NetDebug;

    // expose debugging info to clientside "NetConnection debugger" utility
    mx.remoting.debug.NetDebug.initialize();

    // create, position, and set params on three dynamic text fields: status, node-title, and node-body
    var tf:TextField = this.createTextField("status", 10, 0, 0, 200, 200);
    var ntitle:TextField = this.createTextField("nodetitle", 11, 0, 50, 200, 200);
    var nbody:TextField = this.createTextField("nodebody", 12, 0, 100, 200, 400);
    ntitle.html = true;
    ntitle.multiline = true;
    nbody.html = true;
    nbody.multiline = true;
    nbody.wordWrap = true;

    // establish connection with remote service gateway in Drupal and specify service
    // - /services/amfphp is AMFPHP in Services gateway
    // - node is one of the two default, exposed services in Services module.  The other is view.
    var node:Service = new Service("http://sitedomain/services/amfphp", new Log(), "node", null, null);
    // call service method
    // - load is one of three methods on the default node service
    // - pass in which node to load (hard coded "1" here for node 1)
    // - optional additonal param to node.load is what fields to return (like in a view?).
    // -- array of field names: node.load(1, ['title', 'body']);
    // -- default is to send the entire node.  This example does that.
    var pc:PendingCall = node.load(1);
    // set up response handler functions
    pc.responder = new RelayResponder(this, "getData_Result", "getData_Fault");

    // set default status text
    tf.text = "no response from server yet.";

    // success result handler
    function getData_Result( re:ResultEvent ):Void {
    // re is the object containing the response
    // two properties you can count on being populated for any node are re.result.title and re.result.body
    tf.text = "response:";
    ntitle.htmlText = "<b>Node Title:</b><br/>" + re.result.title;
    nbody.htmlText = "<b>Node Body:</b><br/>" + re.result.body;
    }

    // failure result handler
    function getData_Fault( fe:FaultEvent ):Void {
    tf.text = "error";
    }
  5. CTRL+ENTER to test the movie

The above sample calls the "load" method on the service "node" with a hard-coded parameter of "1" for "node/1". The node service and its methods (load, save, delete) are exposed by the installation of the Services module. Any other methods you wish to call need to be written a Services hook (see the Services handbook).

In a real setting, you would of course consider managing sessions and logins more restrictively.

Troubleshooting this simple example of services in Flash

  • If you are receiving a 403 error on your remoting calls, or if it just does not work, be sure you allow access to the service for that user (Anonymous in this example) under Administration >> User management >> Access control. (step 1 above)
  • Note that for simplicity, Access and Session Keys have been disabled in Services module settings (step 1 above)

About this page

Drupal version
Drupal 5.x

Develop for Drupal

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here