Over the years, many developers have dreamed of using ActionScript on both the client and the server. Today, the Apache Royale™ SDK finally makes it possible.
With asnodec, we’ll get full access to all Node.js APIs, and it’s even possible to require npm modules in ActionScript. We’ll start with a simple example.
For this tutorial, you should install Node.js. The newest Long Term Support (LTS) release is recommended.
Additionally, you will need Apache Royale 0.9.4 or newer. Use the downloads page, or download it from Node Package Manager with
npm install @apache-royale/royale-js -g
Create a new project
- Create a new, empty folder for your project, and name it HelloNode.
- Inside the new project, create a new folder named src. This is where our ActionScript classes will go.
- Inside the src folder, create a file named HelloNode.as, and add the following code:
public class HelloNode
public function HelloNode()
console.log("Hello", process.release.name, process.version);
dns.lookup("localhost", null, dnsLookupCallback);
}private function dnsLookupCallback(error:Object, address:String):void
console.log("The address of localhost is:", address);
In this class, we’re doing two things. First, we’re printing the version of Node to the console. Then, we’re using Node’s built-in dns module to look up an IP address.
Compile the project on the command line
Use the asnodec executable to transpile the HelloNode ActionScript class that you created above for Node.js.
The project should now contain the following files and folders:
Finally, let’s try running our code with Node.js.
Run the project
Inside the js-debug folder, a file named index.js will be created as the entry point for your Node.js project. You can run this script using the
You should see the following output in your console:
Hello node v6.11.0 The address of localhost is: 127.0.0.1
(The Node version number might be different, obviously!)
This is just a simple example, but it gives you a glimpse of how developers can bring ActionScript server-side using Apache Royale and Node.js. By using an established ecosystem like Node.js, ActionScript developers can take advantage of all of the libraries published to NPM and join a large, vibrant community.