Home Reference Source
public class | source

Loader

You can directly use an instance of this class. loader

The Loader class is used to preload files

Constructor Summary

Public Constructor
public

Creates an instance of the Loader class

Method Summary

Public Methods
public

Create a new instance of the Loader

public

get(id: String): Object

Returns a load file by id

public

Returns the cache containing the preloaded files

public

preload(files: Object, progress: Function): Promise

Load a list of files

public

preloadAudio(id: String, url: String, audio: Audio): Promise

Preload an audio file

public

preloadFile(id: String, url: String, request: XMLHttpRequest): Promise

Preload a file using HTTPRequest

public

preloadImage(id: String, url: String, image: Image): Promise

Preload an image

Public Constructors

public constructor() source

Creates an instance of the Loader class

Public Methods

public create(): Loader source

Create a new instance of the Loader

Return:

Loader

The new Loader instance

public get(id: String): Object source

Returns a load file by id

Params:

NameTypeAttributeDescription
id String

Return:

Object

public getCache(): Object source

Returns the cache containing the preloaded files

Return:

Object

public preload(files: Object, progress: Function): Promise source

Load a list of files

Params:

NameTypeAttributeDescription
files Object

Contains a list of files to load with the following structure: { "file1": "url1", "file2": "url2" } or { "file1": { type: "image|audio|file", url: "url1", obj: objectLoader|null } }

progress Function

A callback function with the parameters: "err, id, data, loaded, total"

Return:

Promise

Returns a promise which is resolved upon loading all files, doesn't matter if they failed or not

public preloadAudio(id: String, url: String, audio: Audio): Promise source

Preload an audio file

Params:

NameTypeAttributeDescription
id String

A unique identifier for this file

url String

The audio url to load

audio Audio

The audio oject used to load the asset. If null a new one will be created.

Return:

Promise

Returns a promise which is resolved upon loading

public preloadFile(id: String, url: String, request: XMLHttpRequest): Promise source

Preload a file using HTTPRequest

Params:

NameTypeAttributeDescription
id String

A unique identifier for this file

url String

The file url to load

request XMLHttpRequest

The xhr oject used to load the asset. If null a new one will be created.

Return:

Promise

Returns a promise which is resolved upon loading

public preloadImage(id: String, url: String, image: Image): Promise source

Preload an image

Params:

NameTypeAttributeDescription
id String

A unique identifier for this file

url String

The image url to load

image Image

The image oject used to load the asset. If null a new one will be created.

Return:

Promise

Returns a promise which is resolved upon loading