Class: LoaderResource

PIXI.LoaderResource

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

Can be extended in GlobalMixins.LoaderResource.

new PIXI.LoaderResource (name, url, options)

Name Type Attributes Default 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.

options.crossOrigin string | boolean <optional>

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

options.timeout number <optional>
0

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.

options.loadType PIXI.LoaderResource.LOAD_TYPE <optional>
LOAD_TYPE.XHR

How should this resource be loaded?

options.xhrType PIXI.LoaderResource.XHR_RESPONSE_TYPE <optional>
XHR_RESPONSE_TYPE.DEFAULT

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

options.metadata PIXI.LoaderResource.IMetadata <optional>

Extra configuration for middleware and the Resource object.

Members

blob Blob

used by parsing middleware

children Array<PIXI.LoaderResource> readonly

The child resources this resource owns.

crossOrigin string | boolean

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

data any

The data that was loaded by the resource.

error Error readonly

The error that occurred while loading (if any).

extension string readonly

The extension used to load this resource.

isComplete boolean readonly

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

isDataUrl boolean readonly

Stores whether or not this url is a data url.

isLoading boolean readonly

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.

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.

name string readonly

The name of this resource.

onAfterMiddleware PIXI.Signal

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

The callback looks like LoaderResource.OnCompleteSignal.

onComplete PIXI.Signal

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

The callback looks like LoaderResource.OnCompleteSignal.

onProgress PIXI.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 LoaderResource.OnProgressSignal.

onStart PIXI.Signal

Dispatched when the resource beings to load.

The callback looks like LoaderResource.OnStartSignal.

progressChunk number readonly

The progress chunk owned by this resource.

spritesheet PIXI.Spritesheet

Reference to Spritesheet object created.

texture PIXI.Texture

Texture reference for loading images and other textures.

textures object<string, PIXI.Texture>

Dictionary of textures from Spritesheet.

timeout number

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.

type PIXI.LoaderResource.TYPE readonly

The resource type.

url string readonly

The url used to load this resource.

xhr XMLHttpRequest readonly

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

xhrType string

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

Enums

PIXI.LoaderResource.LOAD_TYPEnumber

The types of loading a resource can use.

Properties:
Name Description
AUDIO

Uses an Audio object to load the resource.

IMAGE

Uses an Image object to load the resource.

VIDEO

Uses a Video object to load the resource.

XHR

Uses XMLHttpRequest to load the resource.

PIXI.LoaderResource.STATUS_FLAGSnumber

The types of resources a resource could represent.

Properties:
Name Description
COMPLETE

Complete

DATA_URL

Data URL

LOADING

Loading

NONE

None

PIXI.LoaderResource.TYPEnumber

The types of resources a resource could represent.

Properties:
Name Description
AUDIO

Audio

IMAGE

Image

JSON

JSON

TEXT

Plain text

UNKNOWN

Unknown

VIDEO

Video

XML

XML

PIXI.LoaderResource.XHR_RESPONSE_TYPEstring

The XHR ready states, used internally.

Properties:
Name Description
BLOB

Blob

BUFFER

ArrayBuffer

DEFAULT

string

DOCUMENT

Document

JSON

Object

TEXT

String

Type Definitions

IMetadata object

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

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

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.

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.

Methods

PIXI.LoaderResource.setExtensionLoadType (extname, loadType) void static

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 PIXI.LoaderResource.LOAD_TYPE

The load type to set it to.

PIXI.LoaderResource.setExtensionXhrType (extname, xhrType) void static

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 PIXI.LoaderResource.XHR_RESPONSE_TYPE

The xhr type to set it to.

abort (message) void

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

Name Type Description
message string

The message to use for the error

complete () void

Marks the resource as complete.

load (cb) void

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

Name Type Attributes Description
cb PIXI.LoaderResource.OnCompleteSignal <optional>

Optional callback to call once the resource is loaded.