How do you include a 2nd .hx file (library file)?

I have a 2nd file called levels.hx that simply has functions with arrays for each level of a game. I would always use include ‘levels.hx’ to have access to the functions in this 2nd file when coding in AS3, but that doesn’t seem to work in Haxe+OpenFL. Is there something I need to add to my project.xml file in order for the project to read this second .hx file?

There’s nothing in particular to do.

The issue here may be the casing, all files needs to start with an upper case first letter in haxe.

From inside your main file you can do new Levels(); or Levels.staticFunction(); directly without adding anything.

It does appear to be reading the 2nd file (Levels.hx) now, however now it doesn’t want to accept the public variables I’ve defined there.

I get: src/Levels.hx:1: characters 0-6 : Unexpected public

Levels.hx

public var sceneCounter:Int = 0;
public var tile:Array<String> = new Array();

public function BlankArea():Void
{    //50px each width
//100px each height
tile = [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ",
		" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ",
		" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ",
		" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ",
		" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ",
		" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ",
		" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ",
		" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ",
		" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ",
		" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ",
		" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "];
}

All content must be wrapped in a class.

Great! I’ll give that a shot. Thanks.

Still no luck. Now it’s looking for a constructor. I’m just looking for a place to put a function that stores level (string) arrays. When I would use the INCLUDE command is AS3, I simply set everything in the second file as public and the main file would read it. No other content was needed. Not sure if this is called a library file or module, but is there a way to do this in OpenFL?

The problem here is that you have instance variable/functions, which requires an object to access.

You need to add static to the variable and function, public static var/public static function
which would then be used as:

Levels.BlankArea();
Level.tile;

Note that these are requirement of haxe, not openfl.

Great got Main.hx to read Level.hx, however, the public variables defined in Main.hx do not seem to be available in Level.hx.

Never mind. Got it (send it over in the function argument parameters).
Thanks for your help!!