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.
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
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.
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.
How do you do this? What do you get?
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.
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.
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);
1 Like
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
1 Like
That’s brilliant! I will try it, thank you
Sorry, I missed that part!