AMFPHP

Update 2008-06-02: I have made a newer version for AMFPHP 1.9, ActionScript 3, Flex and OS X

In this tutorial I’d like to show how to use AMFPHP 1.0. AMFPHP 1.0 is still in beta but will be published soon.

You need the following things to develop with AMFPHP:
Flash MX 2004 Professional
Macromedia Flash Remoting for Flash MX 2004 ActionScript 2.0 (don’t forget to download the remoting sourcefiles. there is a Readme how to handle this).
To test AMFPHP under Windows you also need a local Webserver. I prefer WAMP (Window, Apache, MySQL, PHP).

After starting the WAMP server you have a WAMP icon in the systemtray. Be sure the icon is white otherwise you have to start all services (click trayicon->Start All Sercices).
If you made a default installation WAMP is installed in “C:\wamp” and “C:\wamp\www” is the default directory (DocumentRoot) for your webcontent. You can change this directory by editing the httpd.conf of the Apache webserver (Click the trayicon->Config files->httpd.conf). Edit line 302 to the Document root you like to have e.g.:

DocumentRoot "C:/work/wamp"

Now create a directory in your DocumentRoot where we are going to test AMFPHP e.g. “remoting” (c:\wamp\www\remoting).
Time to downloadd AMFPHP. Currently there is an unofficial beta available at the site of 5 1/2.
Create a directory called “amfphp” in your remoting directory (c:\wamp\www\remoting\amfphp) and extract the zip into it.
Edit the gateway.php in the amfphp-directory:

$gateway->setBaseClassPath("c:/wamp/www/remoting/amfphp/services");

Now you need to download the Test.as and Test.php here.
Copy the Test.php in your services directory (c:/wamp/www/remoting/amfphp/services):

< ?php
class Test{
 
function Test(){
$this->methodTable = array(
"say" => array(
"description" => "says hello",
"access" => "remote", // available values are private, public, remote
"arguments" => array ("message")
)
);
}
 
function say($thing){
return $thing;
}
}
?>

To test our service test we set up the AS 2.o class Test (Test.as):

/**
@class Test
@package com.soenkerohde.remoting
@author feedback@soenkerohde.com
*/
 
import mx.remoting.Service;
import mx.rpc.RelayResponder;
import mx.rpc.FaultEvent;
import mx.rpc.ResultEvent;
import mx.remoting.PendingCall;
import mx.remoting.debug.NetDebug;
 
class com.soenkerohde.remoting.Test {
 
private var service:Service;
 
function Test(){
// This will enable debug output. Open the NetConnectionDebugger to view debug output
// (Window->Other Panels->NetConnectionDebugger)
NetDebug.initialize();
 
// the first parameter is the url targeting the AMFPHP gateway
// the third parameter is the name of the service you like to use
this.service = new Service("http://localhost/remoting/amfphp/gateway.php", null, "Test", null, null);
 
// initiate the remoting call
var pc:PendingCall = this.service.say("AMFPHP rocks!");
pc.responder = new RelayResponder(this, "handleSayHello", "handleRemotingError");
}
 
private function handleSayHello(re:ResultEvent):Void{
trace(re.result);
_root.createTextField("tf",1,0,0,100,12);
var tf:TextField = _root.tf;
tf.autoSize = "left";
tf.text = String(re.result);
}
 
private function handleRemotingError( fault:FaultEvent ):Void{
NetDebug.trace({level:"None", message:"Error: " + fault.fault.faultstring });
}
}

The Test.as has to be located in your CLASSPATH/com/soenkerohde/remoting.

Now open Flash, create a new FLA and enter the following code in the first frame:

_root.app = new com.soenkerohde.remoting.Test();

and export.

That’s it! If you see the text “AMFPHP rocks!” all works fine. Otherwise please report because you misunderstood my tutorial ;) !

Links:
AMFPHP Wiki (Doku)
Flash Livedocs
Flash Remoting Service Panel