Thursday, June 19, 2008

SWHX on Linux



I've made a little progress in getting swhx running on Linux.

SWHX is a really cool alternative to Adobe AIR, and lets you make a Flash application that runs on your local machine. It works by running a Neko process that launches and controls a Flash player on your local system.

It runs on Mac OSX and Windows, but not yet on Linux.

It was a little tricky to find out how to just compile it, so here's what I learned.

First of all, install it like normal:


haxelib setup
haxelib install swhx


Then get the source code from svn on Google Code:


svn checkout http://screenweaver-hx.googlecode.com/svn/trunk/ swhx


Change directory into the sample projects directory and copy the 1-basic to 0-verybasic


cd samples
cp -av 1-basic 0-verybasic
cd 0-verybasic


Replace the App.hx file in there with something more recent:


// App.hx
class App {
static function main() {
// initialize ScreenWeaver HX
swhx.Application.init();
// create a 400x300 window with title "My Application"
var window = new swhx.Window("My Application",400,300);
// creates a remoting server
var server = new neko.net.RemotingServer();
// create a flash object inside this window
var flash = new swhx.Flash(window,server);
// set the HTML attributes of this flash object
flash.setAttribute("src","ui.swf");
// activate the Flash object
flash.start();
// display the window
window.visible = true;
// enter the system event loop (will exit when window is closed)
swhx.Application.loop();
// cleanup SWHX properly
swhx.Application.cleanup();
}
}


Compile and run:


haxe compile.hxml
neko app.n


You should then get a box with a red square in it.