Class: Resource

Tiny.loaders. Resource

Manages the state and loading of a resource and all child resources.

new Tiny.loaders.Resource(name, url, options)

Name Type Description
name string

The name of the resource to load.

url string | Array.<string>

The url for this resource, for audio/video loads you can pass an array of sources.

options object optional

The options for the load.

Name Type Default Description
crossOrigin string | boolean optional

Is this request cross-origin? Default is to determine automatically.

timeout number 0 optional

A timeout in milliseconds for the load. If the load takes longer than this time it is cancelled and the load is considered a failure. If this value is set to 0 then there is no explicit timeout.

loadType Tiny.loaders.Resource.LOAD_TYPE Tiny.loaders.Resource.LOAD_TYPE.XHR optional

How should this resource be loaded?

xhrType Tiny.loaders.Resource.XHR_RESPONSE_TYPE Tiny.loaders.Resource.XHR_RESPONSE_TYPE.DEFAULT optional

How should the data being loaded be interpreted when using XHR?

metadata object optional

Extra configuration for middleware and the Resource object.

Name Type Default Description
loadElement HTMLImageElement | HTMLAudioElement | HTMLVideoElement null optional

The element to use for loading, instead of creating one.

skipSource boolean false optional

Skips adding source(s) to the load element. This is useful if you want to pass in a loadElement that you already added load sources to.

mimeType string | Array.<string> optional

The mime type to use for the source element of a video/audio elment. If the urls are an array, you can pass this as an array as well where each index is the mime type to use for the corresponding url index.

See:

Members

static,readonlyTiny.loaders.Resource.LOAD_TYPEnumber

The types of loading a resource can use.

Properties:
Name Type Default Description
XHR number 1

Uses XMLHttpRequest to load the resource.

IMAGE number 2

Uses an Image object to load the resource.

AUDIO number 3

Uses an Audio object to load the resource.

VIDEO number 4

Uses a Video object to load the resource.

static,readonlyTiny.loaders.Resource.STATUS_FLAGSnumber

The types of resources a resource could represent.

Properties:
Name Type Default Description
NONE number 0
DATA_URL number
COMPLETE number
LOADING number

static,readonlyTiny.loaders.Resource.TYPEnumber

The types of resources a resource could represent.

Properties:
Name Type Default Description
UNKNOWN number 0
JSON number 1
XML number 2
IMAGE number 3
AUDIO number 4
VIDEO number 5
TEXT number 6

static,readonlyTiny.loaders.Resource.XHR_RESPONSE_TYPEstring

The XHR ready states, used internally.

Properties:
Name Type Default Description
DEFAULT string text

string

BUFFER string arraybuffer

ArrayBuffer

BLOB string blob

Blob

DOCUMENT string document

Document

JSON string json

Object

TEXT string text

String

_flagsnumber

The state flags of this resource.

readonlychildrenArray.<Tiny.loaders.Resource>

The child resources this resource owns.

crossOriginstring

Is this request cross-origin? If unset, determined automatically.

dataany

The data that was loaded by the resource.

readonlyerrorError

The error that occurred while loading (if any).

readonlyextensionstring

The extension used to load this resource.

readonlyisCompleteboolean

Describes if this resource has finished loading. Is true when the resource has completely loaded.

readonlyisDataUrlboolean

Stores whether or not this url is a data url.

readonlyisLoadingboolean

Describes if this resource is currently loading. Is true when the resource starts loading, and is false again when complete.

The method of loading to use for this resource.

metadataobject

Extra info for middleware, and controlling specifics about how the resource loads.

Note that if you pass in a loadElement, the Resource class takes ownership of it.
Meaning it will modify it as it sees fit.

Properties:
Name Type Argument Default Description
loadElement HTMLImageElement | HTMLAudioElement | HTMLVideoElement <optional>
null

The element to use for loading, instead of creating one.

skipSource boolean <optional>
false

Skips adding source(s) to the load element. This is useful if you want to pass in a loadElement that you already added load sources to.

readonlynamestring

The name of this resource.

onAfterMiddlewareSignal

Dispatched after this resource has had all the after middleware run on it.

The callback looks like Tiny.loaders.Resource.OnCompleteSignal.

onCompleteSignal

Dispatched once this resource has loaded, if there was an error it will be in the error property.

The callback looks like Tiny.loaders.Resource.OnCompleteSignal.

onProgressSignal

Dispatched each time progress of this resource load updates.
Not all resources types and loader systems can support this event so sometimes it may not be available. If the resource is being loaded on a modern browser, using XHR, and the remote server properly sets Content-Length headers, then this will be available.

The callback looks like Tiny.loaders.Resource.OnProgressSignal.

onStartSignal

Dispatched when the resource beings to load.

The callback looks like Tiny.loaders.Resource.OnStartSignal.

readonlyprogressChunknumber

The progress chunk owned by this resource.

timeoutnumber

A timeout in milliseconds for the load. If the load takes longer than this time it is cancelled and the load is considered a failure. If this value is set to 0 then there is no explicit timeout.

The resource type.

readonlyurlstring

The url used to load this resource.

readonlyxhrXMLHttpRequest

The XHR object that was used to load this resource. This is only set when loadType is Tiny.loaders.Resource.LOAD_TYPE.XHR.

xhrTypestring

The type used to load the resource via XHR. If unset, determined automatically.

Methods

staticTiny.loaders.Resource.setExtensionLoadType(extname, loadType)

Sets the load type to be used for a specific extension.

Name Type Description
extname string

The extension to set the type for, e.g. "png" or "fnt"

loadType Tiny.loaders.Resource.LOAD_TYPE

The load type to set it to.

staticTiny.loaders.Resource.setExtensionXhrType(extname, xhrType)

Sets the load type to be used for a specific extension.

Name Type Description
extname string

The extension to set the type for, e.g. "png" or "fnt"

xhrType Tiny.loaders.Resource.XHR_RESPONSE_TYPE

The xhr type to set it to.

Aborts the loading of this resource, with an optional message.

Name Type Description
message string

The message to use for the error

Marks the resource as complete.

Kicks off loading of this resource. This method is asynchronous.

Name Type Description
cb function optional

Optional callback to call once the resource is loaded.

Type Definitions

Tiny.loaders.Resource.OnCompleteSignal(resource)

When the resource finishes loading.

Name Type Description
resource Tiny.loaders.Resource

The resource that the event happened on.

Tiny.loaders.Resource.OnProgressSignal(resource, percentage)

When the resource reports loading progress.

Name Type Description
resource Tiny.loaders.Resource

The resource that the event happened on.

percentage number

The progress of the load in the range [0, 1].

Tiny.loaders.Resource.OnStartSignal(resource)

When the resource starts to load.

Name Type Description
resource Tiny.loaders.Resource

The resource that the event happened on.

Documentation generated by JSDoc 3.4.3 on Mon Dec 03 2018 17:48:52 GMT+0800 (CST)