Skip to content

Instantly share code, notes, and snippets.

@sonygod
Created April 17, 2013 08:30
Show Gist options
  • Save sonygod/5402715 to your computer and use it in GitHub Desktop.
Save sonygod/5402715 to your computer and use it in GitHub Desktop.
haxe remoting call from js to flash
package ;
//import haxe.Timer;
import js.Browser;
import haxe.remoting.ExternalConnection;
import tink.lang.Cls;
class JsMain {
public static function foo(obj) {
return obj.x + obj.y; }
public static function init() {
run(cnx);
}
public function foo2(obj):String {
return obj.x + obj.y + "foo2";
}
public static var cnx = null;
static var ctx = null;
static var hello:Forwarder;
public static function main() {
ctx = new haxe.remoting.Context();
ctx.addObject("JsMain", JsMain);
ctx.addObject("hello", new HelloService());
ctx.addObject("JsMain2", new JsMain());
cnx = ExternalConnection.flashConnect("default", "myFlashObject", ctx);
hello = new Forwarder(cnx);
}
public static function run(cnx) {
Browser.window.alert( hello.hello("js call", "flash"));
}
public function new() { }
}
class Forwarder implements Cls {
var fields:Hash<Dynamic> = new Hash<Dynamic>();
@:forward(!multiply) var target:ExternalConnection;
@:forward function fwd2(hello:HelloService) {
get: fields.get($name),
set: fields.set($name, param),
call:target.resolve($id).resolve($name).call($args)
}
public function new(target) {
this.target = target;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment