Code sharing

You can call pages/components server methods from the client and vise versa. For that you must mark shared methods with @shared meta and use server() and client() macros to make a call.

Server.hx file:

class Server extends BaseServer
{
    function mybt_click(t, e)
    {
        // you can call client methods from the server on the postback only
        // also remember: method really will be called after ajax process
        // so you can't get return value
        client().sharedMethodB(20);
    }

    @shared function sharedMethodA(s:String, n:Int)
    {
        return s + n; // just example
    }
}

Client.hx file:

class Client extends BaseClient
{
    function init()
    {
        // ajax call server method:
        server().sharedMethodA("test", 10, function(r)
        {
            // here callback function code
            // r is a returned value
            trace(r);
        });
    }

    @shared function sharedMethodB(n:Int)
    {
        trace(n);
    }
}

version #164, modified 2013-01-28 17:17:07 by yar3333