# Is it possible to call external Js function Like flash

**URL:** https://community.haxe.org/t/is-it-possible-to-call-external-js-function-like-flash/2814
**Category:** Haxe
**Tags:** haxe-js
**Created:** [December 16, 2020, 6:20pm UTC](https://community.haxe.org/t/is-it-possible-to-call-external-js-function-like-flash/2814 "2020-12-16T18:20:00Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![youssefmyh](https://community.haxe.org/user_avatar/community.haxe.org/youssefmyh/32/1384_2.png) [@youssefmyh](https://community.haxe.org/u/youssefmyh)
#### Post date: [December 16, 2020, 6:20pm UTC](https://community.haxe.org/t/is-it-possible-to-call-external-js-function-like-flash/2814/1 "2020-12-16T18:20:00Z")

</div>

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

---

<div class="post-metadata">

### Author: ![back2dos](https://community.haxe.org/user_avatar/community.haxe.org/back2dos/32/30_2.png) [@back2dos](https://community.haxe.org/u/back2dos)
#### Post date: [December 17, 2020, 12:17pm UTC](https://community.haxe.org/t/is-it-possible-to-call-external-js-function-like-flash/2814/2 "2020-12-17T12:17:00Z")

</div>

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

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

```

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

Alternatively, you can define externs:

```haxe
@: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.

---

<div class="post-metadata">

### Author: ![youssefmyh](https://community.haxe.org/user_avatar/community.haxe.org/youssefmyh/32/1384_2.png) [@youssefmyh](https://community.haxe.org/u/youssefmyh)
#### Post date: [December 17, 2020, 2:14pm UTC](https://community.haxe.org/t/is-it-possible-to-call-external-js-function-like-flash/2814/3 "2020-12-17T14:14:33Z")

</div>

I tried that but I am always getting this error

Uncaught TypeError: window.GetProposedFriends is not a function

here is my class definition

````haxe
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)
````

---

<div class="post-metadata">

### Author: ![back2dos](https://community.haxe.org/user_avatar/community.haxe.org/back2dos/32/30_2.png) [@back2dos](https://community.haxe.org/u/back2dos)
#### Post date: [December 17, 2020, 2:25pm UTC](https://community.haxe.org/t/is-it-possible-to-call-external-js-function-like-flash/2814/4 "2020-12-17T14:25:30Z")

</div>

Here’s a fully working example: [Try Haxe !](https://try.haxe.org/#57285)

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.

---

<div class="post-metadata">

### Author: ![youssefmyh](https://community.haxe.org/user_avatar/community.haxe.org/youssefmyh/32/1384_2.png) [@youssefmyh](https://community.haxe.org/u/youssefmyh)
#### Post date: [December 18, 2020, 8:56am UTC](https://community.haxe.org/t/is-it-possible-to-call-external-js-function-like-flash/2814/5 "2020-12-18T08:56:56Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![youssefmyh](https://community.haxe.org/user_avatar/community.haxe.org/youssefmyh/32/1384_2.png) [@youssefmyh](https://community.haxe.org/u/youssefmyh)
#### Post date: [December 24, 2020, 10:50am UTC](https://community.haxe.org/t/is-it-possible-to-call-external-js-function-like-flash/2814/6 "2020-12-24T10:50:50Z")

</div>

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

> <https://gist.github.com/pbojinov/8965299>

Thanks and good luck
