HOWTO: Connect Flash to Drupal via XML-RPC

This example assumes you're using Flash MX 2004.

The purpose of this document is to explain how to interface with Drupal via Flash, using XML-RPC.

Flash Setup

  1. Create an empty folder on your computer entitled 'example'. This folder will house the working Flash and library files needed to connect to the Drupal XML-RPC interface.
  2. Visit: http://sourceforge.net/projects/xmlrpcflash and download the "XML-RPC Client for ActionScript 2" (xmlrpcflash_0.9.3.zip). The current version is 0.9.3.
  3. Uncompress xmlrpcflash_0.9.3.zip. This will result in a folder entitled 'com'. Move the 'com' folder to your 'example' folder. The 'com' folder provides the XML-RPC libraries which Flash will use to communicate with the Drupal XML-RPC interface.
  4. Create a new Flash file named 'test.fla' and save it in the 'example' folder.

Flash

The "XML-RPC Client for Actionscript" isn't a terribly complicated beast to tame. To get started, here's a very simple example. Place the following ActionScript code on the first frame of your timeline. Remember to alter the 'url' accordingly.

import com.mattism.http.xmlrpc.Connection;
import com.mattism.http.xmlrpc.ConnectionImpl;
onLoadListing = function (r:Array) {
for (var i = 0; i<r.length; i++) {
trace('method: '+r[i]);
}
};
// the complete url/path to your xmlrpc interface.
var url:String = "http://example.com/xmlrpc.php";
var c:Connection = new ConnectionImpl();
c.setUrl(url);
c.onLoad = onLoadListing;
c.call('system.listMethods');

The end result is a simple list of public methods, returned for posterity sake. What you do with the information is up to you and outside the scope of this document.

Drupal

If you choose to develop a custom module which utilitizes hook_xmlrpc, consult the 'blogapi' module for some great examples.

You can also try another

travist - April 14, 2007 - 05:09

You can also try another method that I wrote about in my tutorial Interfacing Flash with Drupal.

I basically create an interface file that I can use to communicate to my Flash application. It is MUCH easier than going with XML parsing.

More useful example ;-)

d0ublej0 - May 2, 2007 - 23:39

I tried a few hours to get the xml-rpc interface working for flash and drupal. The example mentioned above is nice... but not very usful because it doesn't show the important methods like node.save and node.load. Hopefully I can help other developers to save time by using the code below :

//Create a new node
var node:Object = {title:"Some node",body:"The node body" };
c.addParam(node,XMLRPCDataTypes.STRUCT);
c.call('node.save');

//Load an existing node
var nid               = 18;
var fields :Array = ["title","body"];
c.addParam( nid , "int" );
c.addParam( fields , XMLRPCDataTypes.ARRAY );
c.call('node.load');

Install Service Module First...

dquakenbush - August 15, 2007 - 21:57

turn on the server and "node" service for the service module, and turn off api key, sid, etc, grant permissions, in the service settings.

Then this code magically begins to work ;-)

Using 5.1

drupal_XMLRPC_interface_v0.1

d0ublej0 - August 19, 2007 - 10:08

I've played arround with the XML-RPC Client for ActionScript and implemented an example which allows following xml methods:

- node.load
- node.save
- user.login
- system.connect

The flash app supports api_key and sessid, please make sure that they are enabled in you drupal xmlrpc service.

You can download the first version under http://www.creativity-meets-technology.de/projects/drupal_XMLRPC_interfa... .

 
 

Drupal is a registered trademark of Dries Buytaert.