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.


No comments:

Post a Comment