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 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
-
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 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.<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
error
property.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
0
then 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
loadType
isTiny.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.
-
abort(message)
-
Aborts the loading of this resource, with an optional message.
Name Type Description message
string 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 cb
Resource.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 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.