AssetManager

Ashley's avatar
Medal
Construct Team Founder
Published 6 Sep, 2018
195 words
<1 min

The AssetManager class manages everything in the runtime relating to assets (associated project files). In general project files simply cannot be fetched by their URL, because in preview mode they are only stored locally, and some platforms like Cordova have limitations on being able to fetch URLs so need to use different approaches to read files. AssetManager handles all of these details and should always be used to access any other files in the project.

Methods

GetRuntime()

Return the associated Runtime.

async FetchBlob(url)

Fetch a blob from a given URL. Returns a promise that resolves with the fetched blob. Note this method handles various cross-platform details when used to fetch project files so is preferable if the content being requested will be used as a blob.

async FetchJson(url)

As with FetchBlob(), but returns the content in JSON format.

async LoadProjectFileUrl(filename)

Obtain a URL to a given project filename that can be directly fetched. On some platforms this will be translated to a blob URL; in other cases it will simply return the filename if it can already be directly fetched. Note this method returns a promise that resolves with the URL to use.