Flash/AMF Remoting

Traditional Remoting servers are the Flash Media Server (FMS) and AMFPHP. They both use the AMF protocol over HTTP. This tutorial will introduce a way to do Remoting between an Haxe program and an AMF Remoting Server.

First, you need to setup your AMF Server and setup a service. If you're using AMFPHP, place the following file named HelloWorld.php in your /services directory (this is the same as the AMFPHP Tutorial) :

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

  function say($sMessage) {
    return 'You said: ' . $sMessage;


This file will enable you to access to the service named HelloWorld which has the method say. Now edit the following Haxe program that will call the HelloWorld.say method and display the result :

class AMFTest {
  static function displayResult( r : Dynamic ) {
    trace("result : "+r);

  static function onError( e : Dynamic ) {
      trace("error : "+Std.string(e));

  static function main() {
    var url = "http://localhost/gateway.php";
    var c = haxe.remoting.AMFConnection.urlConnect(url);
    c.HelloWorld.say.call(["Test !"],displayResult);

Compile it by using the following HXML file :

-main AMFTest
-swf amftest.swf

Now open the SWF and if everything is setup correctly it should display result : You said : Test !. You can get back the AMF errors as well, simply try to add the following line to your Haxe program :



Due to the fact that we're using the AMF protocol, some values might not be sent correctly when calling methods. In particular, enums and class instances can't be sent on the server side. Try to stay with basic types for the arguments and methods returns values when using AMF Remoting.

version #3866, modified 2008-07-30 15:40:40 by ncannasse