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.
|
Members
-
static,readonlyTiny.loaders.Resource.LOAD_TYPEnumber
-
The types of loading a resource can use.
Properties:
Name Type Default Description XHRnumber 1 Uses XMLHttpRequest to load the resource.
IMAGEnumber 2 Uses an
Imageobject to load the resource.AUDIOnumber 3 Uses an
Audioobject to load the resource.VIDEOnumber 4 Uses a
Videoobject to load the resource. -
static,readonlyTiny.loaders.Resource.STATUS_FLAGSnumber
-
The types of resources a resource could represent.
Properties:
Name Type Default Description NONEnumber 0 DATA_URLnumber COMPLETEnumber LOADINGnumber -
static,readonlyTiny.loaders.Resource.TYPEnumber
-
The types of resources a resource could represent.
Properties:
Name Type Default Description UNKNOWNnumber 0 JSONnumber 1 XMLnumber 2 IMAGEnumber 3 AUDIOnumber 4 VIDEOnumber 5 TEXTnumber 6 -
static,readonlyTiny.loaders.Resource.XHR_RESPONSE_TYPEstring
-
The XHR ready states, used internally.
Properties:
Name Type Default Description DEFAULTstring text string
BUFFERstring arraybuffer ArrayBuffer
BLOBstring blob Blob
DOCUMENTstring document Document
JSONstring json Object
TEXTstring text String
-
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.
-
loadTypeTiny.loaders.Resource.LOAD_TYPE
-
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 loadElementHTMLImageElement | HTMLAudioElement | HTMLVideoElement <optional>
null The element to use for loading, instead of creating one.
skipSourceboolean <optional>
false Skips adding source(s) to the load element. This is useful if you want to pass in a
loadElementthat you already added load sources to. -
readonlynamestring
-
The name of this resource.
-
onAfterMiddlewareSignal.<Resource.OnCompleteSignal>
-
Dispatched after this resource has had all the after middleware run on it.
The callback looks like Tiny.loaders.Resource.OnCompleteSignal.
-
onCompleteSignal.<Resource.OnCompleteSignal>
-
Dispatched once this resource has loaded, if there was an error it will be in the
errorproperty.The callback looks like Tiny.loaders.Resource.OnCompleteSignal.
-
onProgressSignal.<Resource.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.<Resource.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
0then there is no explicit timeout. -
readonlytypeTiny.loaders.Resource.TYPE
-
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
loadTypeisTiny.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 extnamestring The extension to set the type for, e.g. "png" or "fnt"
loadTypeTiny.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 extnamestring The extension to set the type for, e.g. "png" or "fnt"
xhrTypeTiny.loaders.Resource.XHR_RESPONSE_TYPE The xhr type to set it to.
-
abort(message)
-
Aborts the loading of this resource, with an optional message.
Name Type Description messagestring The message to use for the error
-
complete()
-
Marks the resource as complete.
-
load(cb)
-
Kicks off loading of this resource. This method is asynchronous.
Name Type Description cbResource.OnCompleteSignal 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 resourceTiny.loaders.Resource The resource that the event happened on.
-
Tiny.loaders.Resource.OnProgressSignal(resource, percentage)
-
When the resource reports loading progress.
Name Type Description resourceTiny.loaders.Resource The resource that the event happened on.
percentagenumber The progress of the load in the range [0, 1].
-
Tiny.loaders.Resource.OnStartSignal(resource)
-
When the resource starts to load.
Name Type Description resourceTiny.loaders.Resource The resource that the event happened on.