new Resource(name, url [, options])
Parameters:
| Name | Type | Argument | 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 |
|||||||||||||||||||||||||||||||||||||||||
options |
object |
<optional> |
The options for the load. Properties
|
- Source:
Members
-
<static, readonly> LOAD_TYPE :number
-
The types of loading a resource can use.
Type:
- number
- Source:
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, readonly> STATUS_FLAGS :number
-
The types of resources a resource could represent.
Type:
- number
- Source:
Properties:
Name Type Default Description NONEnumber 0 DATA_URLnumber COMPLETEnumber LOADINGnumber -
<static, readonly> TYPE :number
-
The types of resources a resource could represent.
Type:
- number
- Source:
Properties:
Name Type Default Description UNKNOWNnumber 0 JSONnumber 1 XMLnumber 2 IMAGEnumber 3 AUDIOnumber 4 VIDEOnumber 5 TEXTnumber 6 -
<static, readonly> XHR_RESPONSE_TYPE :string
-
The XHR ready states, used internally.
Type:
- string
- Source:
Properties:
Name Type Default Description DEFAULTstring text string
BUFFERstring arraybuffer ArrayBuffer
BLOBstring blob Blob
DOCUMENTstring document Document
JSONstring json Object
TEXTstring text String
-
_flags :number
-
The state flags of this resource.
Type:
- number
- Source:
-
<readonly> children :Array.<Resource>
-
The child resources this resource owns.
Type:
- Array.<Resource>
- Source:
-
crossOrigin :string
-
Is this request cross-origin? If unset, determined automatically.
Type:
- string
- Source:
-
data :any
-
The data that was loaded by the resource.
Type:
- any
- Source:
-
<readonly> error :Error
-
The error that occurred while loading (if any).
Type:
- Error
- Source:
-
<readonly> isComplete :boolean
-
Describes if this resource has finished loading. Is true when the resource has completely
loaded.Type:
- boolean
- Source:
-
<readonly> isDataUrl :boolean
-
Stores whether or not this url is a data url.
Type:
- boolean
- Source:
-
<readonly> isLoading :boolean
-
Describes if this resource is currently loading. Is true when the resource starts loading,
and is false again when complete.Type:
- boolean
- Source:
-
loadType :Resource.LOAD_TYPE
-
The method of loading to use for this resource.
Type:
- Source:
-
metadata :object
-
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.Type:
- object
- Source:
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 aloadElementthat you already added load sources
to. -
<readonly> name :string
-
The name of this resource.
Type:
- string
- Source:
-
onAfterMiddleware :Signal
-
Dispatched after this resource has had all the after middleware run on it.
The callback looks like Resource.OnCompleteSignal.
Type:
- Signal
- Source:
-
onComplete :Signal
-
Dispatched once this resource has loaded, if there was an error it will
be in theerrorproperty.The callback looks like Resource.OnCompleteSignal.
Type:
- Signal
- Source:
-
onProgress :Signal
-
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 Resource.OnProgressSignal.
Type:
- Signal
- Source:
-
onStart :Signal
-
Dispatched when the resource beings to load.
The callback looks like Resource.OnStartSignal.
Type:
- Signal
- Source:
-
<readonly> progressChunk :number
-
The progress chunk owned by this resource.
Type:
- number
- Source:
-
<readonly> type :Resource.TYPE
-
The resource type.
Type:
- Source:
-
<readonly> url :string
-
The url used to load this resource.
Type:
- string
- Source:
-
<readonly> xhr :XMLHttpRequest
-
The XHR object that was used to load this resource. This is only set
whenloadTypeisResource.LOAD_TYPE.XHR.Type:
- XMLHttpRequest
- Source:
-
xhrType :string
-
The type used to load the resource via XHR. If unset, determined automatically.
Type:
- string
- Source:
Methods
-
<static> setExtensionLoadType(extname, loadType)
-
Sets the load type to be used for a specific extension.
Parameters:
Name Type Description extnamestring The extension to set the type for, e.g. "png" or "fnt"
loadTypeResource.LOAD_TYPE The load type to set it to.
- Source:
-
<static> setExtensionXhrType(extname, xhrType)
-
Sets the load type to be used for a specific extension.
Parameters:
Name Type Description extnamestring The extension to set the type for, e.g. "png" or "fnt"
xhrTypeResource.XHR_RESPONSE_TYPE The xhr type to set it to.
- Source:
-
abort(message)
-
Aborts the loading of this resource, with an optional message.
Parameters:
Name Type Description messagestring The message to use for the error
- Source:
-
complete()
-
Marks the resource as complete.
- Source:
-
load( [cb])
-
Kicks off loading of this resource. This method is asynchronous.
Parameters:
Name Type Argument Description cbfunction <optional>
Optional callback to call once the resource is loaded.
- Source:
Type Definitions
-
OnCompleteSignal(resource)
-
When the resource finishes loading.
Parameters:
Name Type Description resourceResource The resource that the event happened on.
- Source:
-
OnProgressSignal(resource, percentage)
-
When the resource reports loading progress.
Parameters:
Name Type Description resourceResource The resource that the event happened on.
percentagenumber The progress of the load in the range [0, 1].
- Source:
-
OnStartSignal(resource)
-
When the resource starts to load.
Parameters:
Name Type Description resourceResource The resource that the event happened on.
- Source: