Use Haxe API Classes Explicitly

I use Haxe to target Javascript.

I have a package (defined as extern), " phaser ", which contains the Math class and many others. I am using import phaser.*; at the beginning of my files, because I use many classes from this package, and I do not want to prefix them all with phaser. .

I would like to use the Math class from the Haxe API , but if I try to use it (for example, Math.random() ), the compiler thinks I want to use phaser.Math and tells me that it does not have such a function.

Is it possible to explicitly write that I want to use the Haxe Math class, not phaser.Math ?

I tried haxe.Math but no luck ...

Thank you in advance

+5
source share
2 answers

to try

 import Math as HaxeMath; 

then use HaxeMath. * instead of Math. *

Notice nothing special in the name of HaxeMath, you could do

 import Math as Freddy; 

then use freddy. * instead of Math. *: p

+4
source

Two ways to solve it:

  • Use std.Math . e.g. std.Math.floor(1.1); or typedef HxMath = std.Math; , or
  • Add import Math as HxMath; before import phaser.*; . If you are using haxe earlier than 3.2, use in instead of as , i.e. import Math in HxMath; .
+4
source

All Articles