Haxe Reference to rootPath


#1

I have embedded an HTML5 game with lime in the following way:
lime.embed("Main", "game-container", width, height, { rootPath: "game/", parameters: {} });

Is there a way to get a reference to the rootPath option from the Haxe code? I’m trying to load images and I need to know what the root directory is.


#2

Hi Seth10001.

This might not be the most elegant solution but you can get the whole path including rootPath
using Assets.getPath()
http://api.openfl.org/openfl/utils/Assets.html#getPath


#3

I think the best practice is to access root.loaderInfo.parameters of your main Sprite. This is supposed to work the same way like flashvars were used in Flash.


#4

Using Assets.getPath(assetIdString) causes a fatal error with any value for assetIdString. It’s supposed to return null if the asset named in the assetIdString does not exist.


#5

How do you do this? What do you get?


#6

That’s true drmelzie - but as soon as you specify an actually existing asset it’ll return the full path to the asset - including the rootpath.


#7

As I said it’s supposed to return null if the asset named in the assetIdString does not exist. So why is it causing a fatal error by just calling it?

The asset does exist. It is one of several png files in the assets folder that is created by the build.


#8

Unfortunately I don’t know what’s happening in your case drmelzie. It’s working flawlessly over here.
Anyway, I found another solution:
trace(Lib.application.config.rootPath);


#9

In order to do this, you would need to repeat the rootPath parameter:

lime.embed (“Main”, “game-container”, width, height, { rootPath: “game/”, parameters: { rootPath: "game/" } });

Everything in the parameters object is passed onto loaderInfo.parameters at runtime :slight_smile:


#10

That’s brilliant! I will try it, thank you


#11

Sorry, I missed that part! :relaxed: