Is it possible to call external Js function Like flash

Hello,

I have a problem.
Our game has payment java script methods and this methods was called via flash.external.call interface.
but i can’t do the same using openfl.external.call targeting html5

The java scripts payment methods was included during the runtime and the swf file was able to load and call it.

my question how could i include/ call dynamic java script class or function from the same domain ?

Thanks in advance

Let’s assume you have a function like this defined in JavaScript:

function someJavaScriptFunction(arg1, arg2) {
  alert(arg1 + ' hoho ' + arg2);
}

You could call it directly as untyped someJavaScriptFunction(1, 2).

Alternatively, you can define externs:

@:native("window")
extern class External {
    static function someJavaScriptFunction(arg1:Int, arg2:Int):Void;
}

Then External.someJavaScriptFunction(1, 2) will be generated as window.someJavaScriptFunction(1, 2). You can adjust and expand this to fit your specific needs.

I tried that but I am always getting this error

Uncaught TypeError: window.GetProposedFriends is not a function

here is my class definition

package;

/**
 * ...
 * @author 1
 */
@:native("window")
extern class GetProposedFriends 
{

  static function GetProposedFriends():Void;
  
  
}```

Also when I do Inspect Element I can the function there 


![Screen Shot 2020-12-17 at 3.11.15 PM|680x500](upload://xbQiWlzyeT05PKaHWeCXhCSTXnu.png)

Here’s a fully working example: Try Haxe !

Difficult to say without more context. Apparently GetProposedFriends is not available from the global state. You should try to find a way to call GetProposedFriends from the devtools console and then adjust the Haxe code accordingly.

Thank you so much for your help.
Yea I am not able to call the script from dev tools but I could found it and call it when I do inspect
for some reason it’s hidden.

finally,
I found the issue, it was in the Iframe.
I need to build a communication protocol between the iframe and the external Java Scripts functions.

In case some one face the same problem here is the best example

Thanks and good luck

1 Like