How to access variable Openfl from .js

How to access variable openfl from external .js

Example :
I have class Global.hx with static variable abc. Can we access variable abc from another .js (not haxe class)?

I’m from my phone so linking is hard but you need to use a haxe feature called “expose”.

You put @:expose before the variable declaration and then in JavaScript you access it using the the full path. That would be something like your.package.YourClass.yourStaticVar

(Edit: you can expose the entire class and have access to ALL the variables and methods too)

1 Like

Thank you for the information. I can use @:expose on my class and accesss all the variables successful.

I can’t expose my variable only. How to access variable in this case :


class myClass{
@:expose private static var myVar:String = “en”;

I tried myClass.myVar not working.

But myClass.myVar working when I expose entire class like this :


class myClass{
private static var myVar:String = “en”;

Maybe try to replace
private static var
public static var

Ah sorry, but the public static var still same result undefined.

Try @:expose("Global") then in JS try