How to make one externs file and use them in other files?

extern class File {
public static function GetPath(id:String):String;
}

how to use it in Main.hx, in Utils.hx without declaring in each file?

If you put the extern class definition in File.hx then you can do File.GetPath in both Main.hx and Utils.hx.

If you want to avoid the File. part you can import your function with import File.GetPath; and now you’ll have access to GetPath just like if it was in your current class.

And if it’s something you use everywhere you could put the import in the import.hx.

1 Like