Assets.exists & Assets.getPath questions

In my HTML5 projects, the assets I use that I put in an Assets folder end up in an assets folder inside the folder created by the build.

Why does Assets.exists(filename) return false but Assets.exists(assets/filename) return true?

Why does Assets.getPath(filepath) return a string with ?number tacked on the end?

I am using them to try load and play a video file. The code is based on the PlayingVideo example. Locally on my system everything works fine. When on a server with the assets folder placed in a folder named simulation, it doesn’t work.

To make sure that the filepath I use is good, an image file was added to the same folder as the video file. Using simulation/assets/image_name.png, I can successfully load the image. But using simulation/assets/video_name.mp4 gives:

ERROR: There is no asset with an ID of "simulation/assets/video_name.mp4

If I use a nonexistent file name, a standard 404 error is given instead.

What’s the different between a “no asset with an ID of” error and a standard 404 error?

Using Assets.getPath(assets/video_name.mp4 ) returns simulation//assets/video_name.png?125508

Why the // instead just /?

If need be I can post the code for the class I made to load and play a video file.

The assets system is picky about filenames. If your <assets /> tag doesn’t have a rename attribute or has rename="assets", you’ll need to include that every time you call exists() or getPath() or getBitmapData() or whatever.

That’s a cache buster. Without it, an HTML5 game might load old versions of assets.

Generally you shouldn’t mess with the original folder structure. If you want to put everything inside a simulation folder, use <assets path="Assets" rename="simulation/assets" /> to ensure the right path gets compiled into your asset manifest.

You might be able to edit your asset manifest by hand, but you’re on your own there because I’ve never done it.

Minor string concatenation error. AFAIK this never causes issues; all operating systems treat it just like a single slash.

Still don’t understand why using using simulation/assets/video_name.mp4 gives me a “no asset with an ID” while using simulation/assets/image_name.png, I can successfully load the image.

Try getBytes() instead of getPath(), or vice versa. The two perform slightly different checks.

Also, if you’re calling Assets.getPath("assets/video_name.mp4") (without “simulation” anywhere in there), then you should also call Assets.getBytes("assets/video_name.mp4"). The get functions all call getPath() internally, so you want to pass exactly the same string.


As an aside, it sounds like you’re doing something like this:

Assets.getPath("assets/image_name.png"); //no error
Assets.getBitmapData("simulation/assets/image_name.png"); //also no error

If you really are, and you really aren’t seeing any errors, that’s a problem. Either you’re including image assets twice (which wastes space), or your copy of Lime is broken somehow. Lime is not supposed to work that way.

I’m having a similar problem where I’m compiling the project in one folder structure and then moving it to my website where the entire project is in a subfolder from the root (where the project is loaded).

I got the project to load by adding the lime js code below, but the assets folder isn’t considering the rootPath when manually loading images or videos.

lime.embed("Main", "div-container", maxWidth, maxHeight, { rootPath: "sub-folder/", parameters: {} });

With the parameters, the entire project loads correctly, but manually loaded objects from Assets.getPath doesn’t load images/videos correctly.

How can I get Assets.getPath to consider the rootPath parameter?

This sounds like a bug (or an oversight). I think we would want Assets.getPath to consider the rootPath variable

However

It looks like in lime.utils.AssetLibrary, the internal code is saving the rootPath into all the internal paths, so I believe that Assets.getPath would include it.

Do you have a way of taking an OpenFL sample, and modifying it to reproduce the error you are seeing?

openfl create DisplayingABitmap
cd DisplayingABitmap

You might be able to do some tests, to see if Assets.getPath does include the rootPath value or not

Thank you :slight_smile:

My problem is playing a video through a netstream when it’s on the server. I have no problem loading an image from a file. I only tried Assets.getPath instead of specifying the path because I would get the “no asset with an ID” error message.

The video and the image are in simulation/assets/.

Here the code for loading an image (minus the listeners, etc.):

	var sprite=new Sprite();
	var loader:Loader=new Loader();		
	var urlRequest:URLRequest=new URLRequest(path);
	sprite.addChild(loader);
	loader.load(path);

Here’s the code for playing a video:

	var netConnection:NetConnection = new NetConnection();
	netConnection.connect(null);		
	var netStream:NetStream = new NetStream(netConnection);
	netStream.client = { onMetaData: client_onMetaData };
	netStream.play(path,1,5)

The path given to both is simulation/assets/file_name. For both the image and video, Assets.exists(simulation/assets/file_name) returns true. The image is found and loaded. The video gives the “no asset with an ID” error message.

Explanation?

That code isn’t using Assets.getPath to load the image. It’s using the var urlRequest:URLRequest=new URLRequest(path);

I agree with singmajesty, It looks like there is a bug when using the Assets.getPath function at runtime. The even more annoying part is the loader considers the rootPath attribute for the Assets folder. So setting the <assets path="Assets" rename="sub-folder/assets" /> yields an error when loading (sub-folder/sub-folder/assets/image.png not found)

There must be a work around

What does Assets.getPath return? Does it include “sub-folder”? Does it include it twice?