ExternalInterface and HTML5 target

How do I reference the OpenFL HTML5 app from within a HTML page?

In the Haxe/OpenFl code

if (ExternalInterface.available){

works and reaches the host HTML page function:

function getMyData() {

		// BUT how do I reference the OpenFL content to call a function back in the app???


Any help welcomed.

If you haven’t changed the default div id

<div id="openfl-content"></div>


You can use @:expose to do that. Here is an example

public static function myFunction(string:String):void

Then somewhere in your js

1 Like

Thanks justnajm,

We’ve tried that but we get: “TypeError: undefined is not a function (evaluating ‘document.getElementById(‘openfl-content’).f_getTheData()’)”

The function in the HTML5 app is declared as:

public function f_getTheData():Void{



Any thoughts?

My javascript code in the html document

function startGame() {

My Openfl class code:

function onAddedToStage(){
    if (ExternalInterface.available) {
// second argument is for internal function name
        ExternalInterface.addCallback("restartKharchuToys", restartGame); 
private function restartGame() {
    game_end = true;

OK - thanks for your help justnajm (& hcwdikk).

We have it working now by registering the public function with ExternalInterface in the OpenFl code.

What does the final code look like?