How to access variable Openfl from .js

#1

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)?

0 Likes

#2

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

#3

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 :

package;

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 :

package;

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

0 Likes

#4

Maybe try to replace
private static var
by
public static var

0 Likes

#5

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

0 Likes

#6

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

0 Likes