Tutorials Create own backend

From HippoHX

Jump to: navigation, search

To begin with, please note that HippoHX's packager is not (or should not be, tell us if it's otherwise) tied to HippoHX's backend API. The mission of the packager is just pick up your files and mixed them with SWHX's files to create the executables.

Having said that, the idea is that you extend HippoHX's main class so you don't have to worry much about SWHX internals and just add extra API methods you want/need. But this is totally up to you. You might well use the packager and not use the API or the other way round, use the API and not the packager. Now to the point.

On the backend:

  • Create an hx class and extend HippoHX's main class App.hx. This will include all HippoHX's backend APIs letting you add your own.
  • Create your public custom methods.
  • Register your class like this:
private function registerBackends():Void{
		
	context.addObject("myCustomBackend",this);
		
}

You have to override the "registerBackends" method as it's called before creating the SWHX Flash window. Doing this will expose all your public methods to be called from the client.

  • Compile to myapp.n

On the client:

  • From an haXe backend you can call your methods like this:
var cnx = swhx.Connection.desktopConnect();
cnx.myCustomBackend.MyMethod.call([]);

Finally you can pack your app following the Hello World tuto.

PLEASE NOTE that MyMethod must be public if you are compiling to player 9 or above due to AVM2 runtime checking of the public/private modifiers.

You can see a complete working sample in the demo folder.

Personal tools