Remoting Proxy
In the second example we'll use Javascript to make the server side. It isn't really different from the first example.
Server side : Api.hx
package;
class Api
{
static var instance:Api;
public function new()
{
}
static function main()
{
instance = new Api();
var context = new haxe.remoting.Context();
context.addObject("api",instance);
/*Use ExternalConnection class to make connection
with flash*/
haxe.remoting.ExternalConnection.flashConnect("api",null,context);
}
public function check(login:String, pwd:String):Bool
{
return ((login == 'hello' && pwd == 'world')?true:false);
}
}
Client side: ApiClient.hx
/*In this sample our ApiProxy class extends Proxy*/
class ApiProxy extends haxe.remoting.Proxy<Api> { }
class ApiClient {
static var url:String;
static var proxy:ApiProxy;
static function main()
{
/*Use ExternalConnection to connect with Javascrip*/
var cnx = haxe.remoting.ExternalConnection.jsConnect("api");
proxy = new ApiProxy(cnx.api);
/*Call the Api method to display the result*/
display(proxy.check('hello', 'world'));
}
static function display(res:Bool)
{
trace ((res?'You\'re logged in.':'Wrong pwd or login.'));
}
}
Compile and test it :
haxe -js api.js -main Api --next -swf9 ApiClient.swf -main ApiClient
_________
Contact
Follow me