Saturday, November 14, 2009

Testing AMFPHP

1. Create a php class 'HelloWorld.php' with the following code



class HelloWorld
{
    function HelloWorld()
    {
        $this->methodTable = array
        (
            "say" => array
            (
                "access" => "remote",
                "description" => "Pings back a message"
            )
        );
    }

    function say($sMessage)
    {
        $message['message'] = mysql_escape_string( $sMessage );
        return $message;
    }
}
?>




2. Save 'HelloWorld.php' to 'services' folder within your 'amfphp' folder on your webserver ( e.g. '/www/amfphp/services/HelloWorld.php' )




3. Create an Adobe Flex web application with following code and run it




<?xml version="1.0" encoding="utf-8"?>

creationComplete="{this.init()}"
xmlns:mx="http://www.adobe.com/2006/mxml" 
layout="absolute">


import mx.controls.Alert;
private function init():void
{
var myService:NetConnection = new NetConnection ();
myService.connect("http://elimworks.com/amfphp/gateway.php");
var responder:Responder = new Responder( onDataReturned );
     myService.call("HelloWorld.say",  responder , "Hello World" );
}

private function onDataReturned( data:Object ):void
{
Alert.show( data.message , 'Message', Alert.OK );
}
]]>




You should get an Alert pop with the message "Hello World" once you've built and run the application.


Installation Instructions for AMFPHP


I recently attempted to install AMFPHP on my host site. After a few failed attempts, I succeeded. So I decided to document the entire process. If you have any questions, please feel free to email me.

Prerequisite:

  1. A host site ( e.g. 'http://yourhostsite.com' )
  2. You need a webserver with PHP4 ( > 4.3.0 ) or PHP5 installed on it.
  3. Access permission to the Web Root folder ( e.g. 'public_html/www' ).



Install AMFPHP on your webserver

  1. Download a fresh zip file of AMFPHP into a particular destination on your computer . ( e.g. 'C:\AMFPHP' )     Download
  2. Unzip the file within the destination ( e.g. 'C:\AMFPHP\amfphp-1.2.6')
  3. Copy the 'amfphp' folder located in 'C:\AMFPHP\amfphp-1.2.6' into the root folder of your webserver ( e.g. '/www' )
  4. Now we have /www/amfphp
  5. Open up a browser and navigate to http://yourhostsite.com/amfphp/gateway.php'
  6. If AMFPHP has been successfully installed on your web server, you will get a message 'amfphp and this gateway are installed correctly. You may now connect to this gateway from Flash.'.