You can use any Node.js module by calling require and storing it in a variable outside of the package (but you won't get type checking). Assuming that your original JavaScript is valid, this will probably work:
//start code package { public class TestClass() { public function TestClass() { var server = ws.createServer( function (conn) { console.log("new connection"); conn.on("text", function (str) { console.log("收到" + str); for(var i=0;i<10;i++){ str+=str; } conn.sendText(str+"\n"+str); } ) conn.on("close", function (code, reason) { console.log("closed"); } ) } ).listen(8001); console.log("start server"); } } } var ws = require("nodejs-websocket"); //end code Compile with asnodec and run index.js. Here's a full tutorial that I wrote for Apache FlexJS 0.6.0: http://nextgenactionscript.com/tutorials/hello-nodejs-transpile-actionscript-asnodec/ In the next version of Apache FlexJS, it will be possible to have the compiler automatically require modules, with full type checking. The externc compiler in the SDK and my dts2as tool can both output the required metadata when creating an externs SWC. I haven't created a tutorial for any of that yet. However, you can look at how node.swc is built from Google Closure externs in flex-falcon/externs/node. - Josh On Tue, Jul 5, 2016 at 8:57 PM, lizhi <s...@qq.com> wrote: > how run this code. > <pre>var ws = require("nodejs-websocket"); > var server = ws.createServer( > function (conn) { > console.log("new connection"); > conn.on("text", > function (str) { > console.log("收到" + str); > for(var i=0;i<10;i++){ > str+=str; > } > conn.sendText(str+"\n"+str); > } > ) > conn.on("close", > function (code, reason) { > console.log("closed"); > } > ) > } > ).listen(8001); > console.log("start server");</pre> > > > > -- > View this message in context: > http://apache-flex-development.2333347.n4.nabble.com/flexjs-nodejs-tp53677.html > Sent from the Apache Flex Development mailing list archive at Nabble.com. >