Flash, Haxe, NME, SWHX - Web, Desktop, Mobile : Everywhere, do what you want !

05.12.2012 4432 0

I've taken the old Haxe/Flash sources of this app. I had to do some minor fixes in order to make it working with the last Haxe official release...and going this way, I've also made changes to make it ready for the comming-soon Haxe 3 ! ( Read here for more informations about Haxe 3 )

The NME case

Then I had to deal with embedded assets. For this app, I only embed a font. The other pictures are loaded at runtime, that's why I haven't proceed like here with a separated Asset class, but I use a simple compilation directive
com/filt3rek/fdockhx/Dock.hx :

#if nme
    tfx.font    = Assets.getFont( "tahomabd" ).fontName;
    tfx.font 	= new TahomaBold().fontName;

This means that my building scripts looks like that :
Haxe/Flash HXML build script :

-swf-lib assets/fonts/tahomabd.swf

Note : I use this wonderful tool written in Haxe : HxSWFML in order to embed the font into a SWF.
NME NMML build script :

<assets path="assets">
    <font path="fonts/tahomabd.ttf" id="tahomabd" />

That's all for now ! I have an app that works now on HTML5, on my desktop as an executable (neko or cpp) and of course on the Flash Player.
Note : This app compiles also well for mobile devices as iOS, Android or Blackberry. But since it's not really adapted for tactil touching, I haven't tested it on that plateforms.

The SWHX case

Maybe you remember this post, written more than 4 years ago as an exemple of using Flash & ScreenWeaverHX to build Desktop Applications ?
So, here nothing special neither. The client side is a simple SWF, this one, made yet, adding the swhx.Connection :

// SWHX Connection
_swhxCnx = swhx.Connection.desktopConnect();
_swhxCnx.App.onFlashInitialized.call( [] );

Then, SWHX needs also a server side that is the system layer for the Flash application.
I've taken the same source (App.hx) as in the old post and have just made some minor fixes as for the client part, to update the source for Haxe 3

Note : I've made some modifications too in the SWHX library in order to make it Haxe 3 Ready .
You can download swhx-Hx3Ready.zip here.

The click event case

Ok, I have my app that runs everywhere. But the final goal of this app is to give you shortcuts for your favorite programs or websites.
I have decided to separate the app into 2 spaces : web and desktop. So I have a redirection in the Flash and HTML5 cases and a process launching on the sys platforms as neko (swhx as well) and c++ for now.
The final click callback function looks like that :

function click( e : DockIcon ) {
    var path = e.path;
    #if js					// JS redirection (Ajax or not)
	if ( path.startsWith( 'http://' ) )
	    untyped __js__( "document.location.href=path" );
	    untyped __js__( "window.parent.SWFAddress.setValue( path )" );
    #elseif ( !swhx && flash ) 			// Flash redirection (Ajax or not)
	if ( path.startsWith( 'http://' ) )
	    Lib.getURL( new URLRequest( e.path ) );
	    if( flash.external.ExternalInterface.available )
		_jsCnx.SWFAddress.setValue.call( [ e.path ] );
	#elseif swhx				// SWHX call
	    _swhxCnx.App.launch.call( [ path ] );
	#elseif ( sys || neko || cpp )		// Sys call
		new sys.io.Process( path, [] );
	    }catch( e : Dynamic ) {}

Note : For my personal needs, I've done here 2 kind of redirection (Ajax or not) for JS(HTML5) or Flash.
For the system plateforms, it's a process creation for the NME targets and a remote call for SWHX.

The boot case

The app has to load a configuration XML file that handles the names, paths and icons of the shortcuts.
Thanks to compilation directives again, I've quickly managed that like that :

public static function main() {
    // Entry Point
    #if js
	return;    // too lazy to add custom build for js [:P]
    instance = new FDock();
    var url = "";
    #if ( !swhx && flash )			// Flash without NME
	url	= Lib.current.loaderInfo.parameters.urlConfig;
	if( flash.external.ExternalInterface.available )
	    _jsCnx    = haxe.remoting.ExternalConnection.jsConnect( "default" );	
    #elseif swhx				// Flash using SWHX
	// SWHX Connection
	_swhxCnx = swhx.Connection.desktopConnect();
	_swhxCnx.App.onFlashInitialized.call( [] );
    #elseif ( sys || neko || cpp )		// NME
	var arg = Sys.args()[ 0 ];
	url = arg != null ? arg : "";
    instance.run( url != "" ? url : "fdockhx.xml" );

Here, for all plateforms, if the path of the configuration file is not specified, a default one fdockhx.xml, located near the app is taken.
For the Flash plateform, the traditional way of flashvars is used, looking for a param named urlConfig like that :

url    = Lib.current.loaderInfo.parameters.urlConfig

For the system plateforms, an argument can be added when launching the app like that :

FDockHxNME.exe path/to/my/config.xml

For HTML5/Javascript, I wanted to run the app by myself so I've added these lines in the HTML file :

<script type="text/javascript">
    var fdock = new com.filt3rek.fdockhx.FDock();
    fdock.run( '../../../assets/data/fdockhx_web.xml' );

Note : Note, note, note, of course that I'm too lazy to remove the call to the main function in the Javascript output, so I "return" in case of js...arf

Result and sources

All the sources and the build scripts can be found here.
The Flash version can be seen here.
The HTML5 version can be seen here.
You can download the Windows SWHX executables here.
You can download the Windows NME Neko executables here.
You can download the Windows NME C++ executables here.
Everyday, it's a pleasure to work with Haxe, nothing more to say...


Laisser un commentaire