Accessing Embedded files

I’m messing around with embedding files and I am curious how do I get the assets that are embedded? Like, say I wanted to get an asset ./assets/background.png and the ./assets/ folder is embedded?

If I’m completely misinterpreting what embedding a file actually does, I’m sorry

in project.xml you add this to embed your images that are in assets/images folder
<assets path="assets/images" include="*.png" embed="true" />
and in code it would be "assets/images/background.png"

also you can rename the path (an alias) you would use in code like this
<assets path="assets/images" rename="img" include="*.png" embed="true" />
and in code it would be "img/background.png"

In the case of a windows build, when you embed the images, or other assets, they are embedded in the exe itself and no folders are in the build. For HTML5 the folders and files are included in the build, but you access them the same way.

Hope it helps.

I was more of meaning how do I actually access them because the file paths for the files aren’t actually there anymore. Using your example /img/background.png/ doesn’t work because that isn’t a valid path?

You need to use the Assets class to access the assets that you embedded.

Something like this, I believe: Assets.getBitmapData("assets/background.png")

If using that path as the asset id isn’t exactly correct, you can check the result of Assets.list() to get the proper id.

1 Like