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 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, readonly> STATUS_FLAGS :number
-
The types of resources a resource could represent.
Type:
- number
- Source:
Properties:
Name Type Default Description NONE
number 0 DATA_URL
number COMPLETE
number LOADING
number -
<static, readonly> TYPE :number
-
The types of resources a resource could represent.
Type:
- number
- Source:
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, readonly> XHR_RESPONSE_TYPE :string
-
The XHR ready states, used internally.
Type:
- string
- Source:
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
-
_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 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 aloadElement
that 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 theerror
property.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
whenloadType
isResource.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 extname
string The extension to set the type for, e.g. "png" or "fnt"
loadType
Resource.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 extname
string The extension to set the type for, e.g. "png" or "fnt"
xhrType
Resource.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 message
string 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 cb
function <optional>
Optional callback to call once the resource is loaded.
- Source:
Type Definitions
-
OnCompleteSignal(resource)
-
When the resource finishes loading.
Parameters:
Name Type Description resource
Resource The resource that the event happened on.
- Source:
-
OnProgressSignal(resource, percentage)
-
When the resource reports loading progress.
Parameters:
Name Type Description resource
Resource The resource that the event happened on.
percentage
number The progress of the load in the range [0, 1].
- Source:
-
OnStartSignal(resource)
-
When the resource starts to load.
Parameters:
Name Type Description resource
Resource The resource that the event happened on.
- Source: