Amfphp + Drupal + Flash8

Kirupa has always been a nice blog, so I decided to post here a very simple tutorial to retrieve a node from Drupal using AMFPHP and Flash 8.

To be shorter. You have to have Drupal installed as your CSM. Be sure you have a nice host that doesn’t have any restrictions to AMFPHP module. If your server does have restrictions, you won’t get it working.

So download and install in Drupal the following modules (www.drupal.org)

Services
AMFPHP
AMFPHP Beta 2 > that shall be installed inside the AMFPHP folder.

Enable your modules inside Drupal and be sure to set permission for the module Services.
Then in services settings turn off Sessid and Keys.

You have also to enable Clean URLs inside Drupal otherwise you won’t get it working

So here comes the Flash part. First you have to install Flash Remoting Components. Those you can download at:

http://www.adobe.com/products/flashremoting/downloads/components/

After installing your components, open a new flash document.

Go to Common Libraries> Remoting and drag your components to the stage just to get them in your library. Delete both.

In Frame 1 paste this action script:

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;
mx.remoting.debug.NetDebug.initialize();

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;

var node:Service = new Service(“http://mysite.com/services/amfphp”, new Log(), “node”, null, null);

var pc:PendingCall = node.load(1);
pc.responder = new RelayResponder(this, “getData_Result”, “getData_Fault”);

tf.text = “no response from server yet.”;

function getData_Result( re:ResultEvent ):Void {

tf.text = “response:”;
ntitle.htmlText = “<b>Node Title:</b><br/>” + re.result.title;
nbody.htmlText = “<b>Node Body:</b><br/>” + re.result.body;
}

function getData_Fault( fe:FaultEvent ):Void {
tf.text = “error”;
}

The url above is fro Drupal installed in the webroot. If you have a directory for Drupal it should be http://mysite.com/drupal/services/amfphp

If you get an error you can use NetConnection Debugger to find out what happened.

Just open Window>…>NetConnection Debbuger and test your movie again.

In some server you will have to set the config-services.xml inside amfphp>browser directory and set the uri to the correct path.

Hope that help those who wants to know more about AMFPHP and Flash. So AMFPHP is for flash remoting services.

Bye
Gabriela