API Docs for:
Show:

AssetDownloader Class

This object is designed to make asset downloading easy. It chooses which method should be used to download the asset based on the file extension. It has added functionality for dealing with inconsistencies in audio file support between browsers.

Constructor

AssetDownloader

()

Item Index

Methods

download

(
  • assetPath
  • downloadedCallback
)

The download method used by this function depends on the file extension. For image assets, the Image object will be used, for audio assets the Audio object and all other assets will be downloaded using the XMLHttpRequest object and returned as string.

Parameters:

  • assetPath String

    File path of the asset to be downloaded.

  • downloadedCallback Function

    A function that will be called back with the asset as the argument once the download is finished.

setAudioTypes

(
  • type
)

The downloader will use the MIME type information to deal with inconsistencies in audio support between browsers. If a requested audio file can't be played by the browser, then the downloader will attempt to load a file with the same name, but an extension that can be played. Due to this functionality it is important to only set audio types that you will actualy provide as alternatives if you want to rely on the feature.

Parameters:

  • type Array multiple

    File extensions and their corresponding MIME types signifying assets that should be treated as audio files.

Example:

   assetDownloader.setAudioTypes(['mp3', 'audio/mpeg'],['wav', 'audio/wav']);

setImageTypes

(
  • type
)

Parameters:

  • type String multiple

    File extensions signifying assets that should be treated as images.

Example:

   assetDownloader.setImageTypes('png', 'jpg', 'jpeg');