Remoting Proxy

I'm going to give you two examples of remoting proxy usage . First one is between Flash and PHP. The server side is made with PHP and the client side with Flash. In the second example, the server side is Javascript and Flash is still the client side. 

In our PHP/Flash example, the client (flash) use a server function (php) to check parameters tansmited (login and password) and it (flash) displays message returned by the server (php).

Server side : Api.hx

package;
      class Api
      {
      		static var instance:Api;
      		public function new()
      		{
      			
      		}
      		static function main()
      		{
      			/*Create a new instance of our class*/
      			instance = new Api();

      			/*Create new remoting context*/
      			var context = new haxe.remoting.Context();

      			/*Add our new instance into our context because
      			our class can't be automatically accessed.*/
      			context.addObject("api",instance); 
      			haxe.remoting.HttpConnection.handleRequest(context);
      			
      		}
      		
      		public function check(login:String, pwd:String):Bool
      		{
      			  return ((login == 'hello' && pwd == 'world')?true:false);
      		}
      } 

Client Side : ApiClient.hx

import haxe.remoting.HttpAsyncConnection; 

/*Create ApiProxy class which extends haxe.remoting.AsyncProxy<Api>.
The compiler will load the Api class and will list all its public
 instance methods. */
class ApiProxy extends haxe.remoting.AsyncProxy<Api> { }

class ApiClient {
	 static var url:String; 
	 static var cnx:HttpAsyncConnection; 
	 static var proxy:ApiProxy;

	static function main()
	{
		url = "index.php";

		/*Use HttpAsyncConnection wich will return
		an asynchronous connection to the given URL*/
		cnx = HttpAsyncConnection.urlConnect(url);

		/*just set an error handler*/
		cnx.setErrorHandler(function(e) trace(e));

		/*Call our ApiProxy*/
		proxy = new ApiProxy(cnx.api);

		/*Call check() method (Api method) and add the callback method 
		to see any response */
		proxy.check('hello', 'world', display);

		
	}  
	static function display(res:Bool)
	{
		trace ((res?'You\'re logged in.':'Wrong pwd or login.'));
	}
} 

Compile and test it :

haxe -php ./ -main Api --next -swf9 ./ApiClient.swf -main ApiClient 
(23 times)