I use Haxe targeting Javascript.
I have a package (defined as an extern), "phaser", that contains a Math class along with many others.
I use import phaser.*; at the beginning of my files because I use many classes from this package and I don't want to prefix them all with phaser..
I would like to use the Math class from Haxe API, but if I try to use it (e.g Math.random()), the compiler thinks I want to use phaser.Math and tells me there is no such function in it.
Can I explicitly write that I want to use Haxe Math class and not phaser.Math ?
I've tried haxe.Math but no luck...
Thanks in advance
Try
import Math as HaxeMath;
then use HaxeMath.* instead of Math.*
Note, nothing special about the name HaxeMath, you could do
import Math as Freddy;
then use Freddy.* instead of Math.*. :p
Two ways to solve it:
std.Math. e.g. std.Math.floor(1.1);, or typedef HxMath = std.Math;, orimport Math as HxMath; before import phaser.*;. If you're using a haxe version earlier than 3.2, use in instead of as, i.e. import Math in HxMath;.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With