Haxe Remoting : LocalConnection

07.08.2007 4690 1

Her's a sample, that shows communication between 2 SWFs.
Let's see the code
Receiver.hx :

import haxe.remoting.LocalConnection;
class Receiver
{
    static var lc    : LocalConnection;
    static function main()
    {
        lc = LocalConnection.connect( "_canal" );
    }
    static function myFunction( s : String )
    {
        trace( "myFunction : " + s );
    }
}

Sender.hx :

import haxe.remoting.LocalConnection;
class Sender
{
    static var lc    : LocalConnection;
    
    static function main()
    {
        lc = LocalConnection.connect( "_canal" );
        lc.onError = function ( e ) { trace ( "error : " + e ); };
        lc.Receiver.myFunction.call( [ "Test" ] );
    }
}

As we can see, once the 2 SWFs initialized, we call any function we need with this synthax :
myLocalConnection.myPackage.myClass.myFunction.call( [ params ] );
Download sample

Note:

  • call takes another optionnal param, a function  : ?onData : Dynamic -> Void called when communication succeed.
  • If using flash9, becareful with the ExternalInterface that must be available, and don't forget the famous sandbox security
  • LocalConection.connect takes a String param, that is the communication channel between SWFs. This param must begin with an "_" for using with network (this note is true for the native Flash LocalConnection first)

Commentaires

10.08.2007 à 22:40 hx_alias

cool! thanks for sharing gotta love Haxe!!

Laisser un commentaire

http://
×