External Interface using global javascript scope

Hello,

I was trying to call a function from OpenFL to the wrapping HTML.

I could do it, but it seems that the name i pass in ExternalInterface.call("") is the name of the function in the global javascript scope.

It doesn’t seem right, it can bring issues in case of multiple openFL integration. I was expected to see a lime function that would make the link between the function name that External.call is calling, and the actual javascript function that will be associated with it.

something like
lime.exposeFunction(“function name”, my_function);

where my_function is the implemented function

Cheers

In my case, I set up something like your exposeFunction example in the page javascript and used a generic ‘SendExternalMessage’ ExternalInterface function to call those mapped functions

ExternalInterface.call("SendExternalMessage", 
  {
    fn: FUNCTION_NAME_STRING,
    params : { }
  });

Good idea ! that’s a lot better already, this way, only one variable polute the global scope which is not so bad

You can also use untyped __js__ or extern classes when building to HTML5

thanks, but if i understand well,
that doesn’t adress my problem, that will make a direct relation between my compiled haxe code and the window global js scope, which is not really a good practice.