Created
April 16, 2013 08:14
-
-
Save sonygod/5394290 to your computer and use it in GitHub Desktop.
base communication between js and flash test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * base communication between js and flash test | |
| * | |
| */ | |
| package ; | |
| import haxe.remoting.ExternalConnection; | |
| import haxe.remoting.Context; | |
| import haxe.Timer; | |
| class Main { | |
| static function main() { | |
| #if flash | |
| FlashMain.main(); | |
| #elseif js | |
| JsMain.main(); | |
| #end | |
| } | |
| } | |
| class FlashMain { | |
| static function foo(x, y) { return x + y; } | |
| public static function main() { | |
| var ctx = new Context(); | |
| ctx.addObject("FlashMain", FlashMain); | |
| #if flash | |
| var js =haxe.remoting.ExternalConnection.jsConnect("default",ctx); | |
| trace(js.JsMain.foo.call([ { x:1, y:2 } ])); | |
| trace(js.JsMain2.foo2.call([{x:1,y:2}])); | |
| #end | |
| } | |
| public static function jsTimerCall():Void { | |
| trace("hello"+Timer.stamp()*1000); | |
| } | |
| } | |
| class JsMain { | |
| static function foo(obj) { | |
| return obj.x + obj.y; } | |
| function foo2(obj):String { | |
| return obj.x + obj.y+"foo2"; | |
| } | |
| static function test() { | |
| // GlobalTimer.setInterval(run, 1000,[]); | |
| #if js | |
| js.Browser.window.alert("flash call now"); | |
| #end | |
| } | |
| static var cnx = null; | |
| public static function main() { | |
| var ctx =new Context(); | |
| var hl = new HelloService(); | |
| ctx.addObject("JsMain", JsMain); | |
| ctx.addObject("JsMain2", new JsMain()); | |
| #if js | |
| cnx = ExternalConnection.flashConnect("default", "myFlashObject", ctx); | |
| #end | |
| } | |
| static function run() { | |
| cnx.FlashMain.foo.call([1, 2]); | |
| } | |
| public function new () { } | |
| } | |
| /** | |
| <html> | |
| <head> | |
| <script type="text/javascript" src="remoting.js"></script> | |
| </head> | |
| <body bgcolor="#eeeeee" onLoad="setTimeout('JsMain.run()',200)"> | |
| <div id="haxe:trace"></div> | |
| <object | |
| classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" | |
| codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" | |
| width="400" | |
| height="300" | |
| id="myFlashObject" | |
| > | |
| <param name="movie" value="remoting.swf"/> | |
| <param name="allowScriptAccess" value="always" /> | |
| <param name="quality" value="high" /> | |
| <param name="salign" value="lt" /> | |
| <param name="scale" value="noscale" /> | |
| <param name="menu" value="false" /> | |
| <param name="bgcolor" value="#ffffff"/> | |
| <embed | |
| src="remoting.swf" | |
| quality="high" | |
| salign="lt" | |
| width="400" | |
| height="300" | |
| align="middle" | |
| scale="noscale" | |
| menu="false" | |
| bgcolor="#ffffff" | |
| name="myFlashObject" | |
| swLiveConnect="true" | |
| allowScriptAccess="always" | |
| type="application/x-shockwave-flash" | |
| pluginspage="http://www.macromedia.com/go/getflashplayer" | |
| /> | |
| </object> | |
| </body> | |
| </html> | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment