API Documentation for: 0.6.0
Show:

AbstractLoader Class

Extends EventDispatcher
Defined in: AbstractLoader:41
Module: PreloadJS

The base loader, which defines all the generic methods, properties, and events. All loaders extend this class, including the LoadQueue.

Methods

_createRequest

() protected

Defined in _createRequest:542

Create an internal request used for loading. By default, an XHRRequest or TagRequest is created, depending on the value of PreferXHR:property. Other loaders may override this to use different request types, such as ManifestLoader, which uses JSONLoader or JSONPLoader under the hood.

_createTag

(
  • src
)
HTMLElement protected

Defined in _createTag:558

Create the HTML tag used for loading. This method does nothing by default, and needs to be implemented by loaders that require tag loading.

Parameters:

Returns:

HTMLElement:

The tag that was created

_dispatchEvent

(
  • eventObj
  • eventPhase
)
protected

Parameters:

_isCanceled

() Boolean protected

Defined in _isCanceled:636

Determine if the load has been canceled. This is important to ensure that method calls or asynchronous events do not cause issues after the queue has been cleaned up.

Returns:

Boolean:

If the loader has been canceled.

_sendComplete

() protected

Defined in _sendComplete:601

Dispatch a complete Event. Please see the complete event

_sendError

(
  • event
)
protected

Defined in _sendError:621

Dispatch an error Event. Please see the error event for details on the event payload.

Parameters:

  • event ErrorEvent

    The event object containing specific error properties.

_sendLoadStart

() protected

Defined in _sendLoadStart:568

Dispatch a loadstart Event. Please see the loadstart event for details on the event payload.

_sendProgress

(
  • value
)
protected

Defined in _sendProgress:579

Dispatch a ProgressEvent.

Parameters:

  • value Number | Object

    The progress of the loaded item, or an object containing loaded and total properties.

addEventListener

(
  • type
  • listener
  • [useCapture]
)
Function | Object

Adds the specified event listener. Note that adding multiple listeners to the same function will result in multiple callbacks getting fired.

Example

 displayObject.addEventListener("click", handleClick);
 function handleClick(event) {
    // Click happened.
 }

Parameters:

  • type String

    The string type of the event.

  • listener Function | Object

    An object with a handleEvent method, or a function that will be called when the event is dispatched.

  • [useCapture] Boolean optional

    For events that bubble, indicates whether to listen for the event in the capture or bubbling/target phase.

Returns:

Function | Object:

Returns the listener for chaining or assignment.

buildPath

() deprecated protected

Defined in buildPath:703

Deprecated: Use the {{#crossLink "RequestUtils"}}{{/crossLink}} method {{#crossLink "RequestUtils/buildPath"}}{{/crossLink}} instead.

cancel

()

Defined in cancel:498

Close the the item. This will stop any open requests (although downloads using HTML tags may still continue in the background), but events will not longer be dispatched.

destroy

()

Defined in destroy:508

Clean up the loader.

dispatchEvent

(
  • eventObj
)
Boolean

Dispatches the specified event to all listeners.

Example

 // Use a string event
 this.dispatchEvent("complete");

 // Use an Event instance
 var event = new createjs.Event("progress");
 this.dispatchEvent(event);

Parameters:

  • eventObj Object | String | Event

    An object with a "type" property, or a string type. While a generic object will work, it is recommended to use a CreateJS Event instance. If a string is used, dispatchEvent will construct an Event instance with the specified type.

Returns:

Boolean:

Returns the value of eventObj.defaultPrevented.

getItem

() Object

Defined in getItem:423

Available since 0.6.0

Get a reference to the manifest item that is loaded by this loader. In some cases this will be the value that was passed into LoadQueue using loadFile or loadManifest. However if only a String path was passed in, then it will be a LoadItem.

Returns:

Object:

The manifest item that this loader is responsible for loading.

getLoadedItems

() Array

Defined in getLoadedItems:529

Available since 0.6.0

Get any items loaded internally by the loader. The enables loaders such as ManifestLoader to expose items it loads internally.

Returns:

Array:

A list of the items loaded by the loader.

getResult

(
  • [raw=false]
)
Object

Defined in getResult:436

Available since 0.6.0

Get a reference to the content that was loaded by the loader (only available after the Complete:event event is dispatched.

Parameters:

  • [raw=false] Boolean optional

    Determines if the returned result will be the formatted content, or the raw loaded data (if it exists).

Returns:

getTag

() Object

Defined in getTag:449

Available since 0.6.0

Return the tag this object creates or uses for loading.

Returns:

Object:

The tag instance

handleEvent

(
  • The
)
protected

Defined in handleEvent:661

Available since 0.6.0

Handle events from internal requests. By default, loaders will handle, and redispatch the necessary events, but this method can be overridden for custom behaviours.

Parameters:

  • The Event

    event that the internal request dispatches.

hasEventListener

(
  • type
)
Boolean

Indicates whether there is at least one listener for the specified event type.

Parameters:

  • type String

    The string type of the event.

Returns:

Boolean:

Returns true if there is at least one listener for the specified event.

initialize

() deprecated protected

REMOVED. Removed in favor of using MySuperClass_constructor. See extend and promote for details.

There is an inheritance tutorial distributed with EaselJS in /tutorials/Inheritance.

load

()

Defined in load:469

Begin loading the item. This method is required when using a loader by itself.

Example

 var queue = new createjs.LoadQueue();
 queue.on("complete", handleComplete);
 queue.loadManifest(fileArray, false); // Note the 2nd argument that tells the queue not to start loading yet
 queue.load();

off

(
  • type
  • listener
  • [useCapture]
)

Inherited from EventDispatcher: off:254

A shortcut to the removeEventListener method, with the same parameters and return value. This is a companion to the .on method.

Parameters:

  • type String

    The string type of the event.

  • listener Function | Object

    The listener function or object.

  • [useCapture] Boolean optional

    For events that bubble, indicates whether to listen for the event in the capture or bubbling/target phase.

on

(
  • type
  • listener
  • [scope]
  • [once=false]
  • [data]
  • [useCapture=false]
)
Function

Inherited from EventDispatcher: on:182

A shortcut method for using addEventListener that makes it easier to specify an execution scope, have a listener only run once, associate arbitrary data with the listener, and remove the listener.

This method works by creating an anonymous wrapper function and subscribing it with addEventListener. The created anonymous function is returned for use with .removeEventListener (or .off).

Example

    var listener = myBtn.on("click", handleClick, null, false, {count:3});
    function handleClick(evt, data) {
        data.count -= 1;
        console.log(this == myBtn); // true - scope defaults to the dispatcher
        if (data.count == 0) {
            alert("clicked 3 times!");
            myBtn.off("click", listener);
            // alternately: evt.remove();
        }
    }

Parameters:

  • type String

    The string type of the event.

  • listener Function | Object

    An object with a handleEvent method, or a function that will be called when the event is dispatched.

  • [scope] Object optional

    The scope to execute the listener in. Defaults to the dispatcher/currentTarget for function listeners, and to the listener itself for object listeners (ie. using handleEvent).

  • [once=false] Boolean optional

    If true, the listener will remove itself after the first time it is triggered.

  • [data] optional

    Arbitrary data that will be included as the second parameter when the listener is called.

  • [useCapture=false] Boolean optional

    For events that bubble, indicates whether to listen for the event in the capture or bubbling/target phase.

Returns:

Function:

Returns the anonymous function that was created and assigned as the listener. This is needed to remove the listener later using .removeEventListener.

removeAllEventListeners

(
  • [type]
)

Removes all listeners for the specified type, or all listeners of all types.

Example

 // Remove all listeners
 displayObject.removeAllEventListeners();

 // Remove all click listeners
 displayObject.removeAllEventListeners("click");

Parameters:

  • [type] String optional

    The string type of the event. If omitted, all listeners for all types will be removed.

removeEventListener

(
  • type
  • listener
  • [useCapture]
)

Removes the specified event listener.

Important Note: that you must pass the exact function reference used when the event was added. If a proxy function, or function closure is used as the callback, the proxy/closure reference must be used - a new proxy or closure will not work.

Example

 displayObject.removeEventListener("click", handleClick);

Parameters:

  • type String

    The string type of the event.

  • listener Function | Object

    The listener function or object.

  • [useCapture] Boolean optional

    For events that bubble, indicates whether to listen for the event in the capture or bubbling/target phase.

setTag

(
  • tag
)

Defined in setTag:459

Available since 0.6.0

Set the tag this item uses for loading.

Parameters:

toString

() String

Inherited from EventDispatcher but overwritten in toString:713

Returns:

String:

a string representation of the instance.

willTrigger

(
  • type
)
Boolean

Indicates whether there is at least one listener for the specified event type on this object or any of its ancestors (parent, parent's parent, etc). A return value of true indicates that if a bubbling event of the specified type is dispatched from this object, it will trigger at least one listener.

This is similar to hasEventListener, but it searches the entire event flow for a listener, not just this object.

Parameters:

  • type String

    The string type of the event.

Returns:

Boolean:

Returns true if there is at least one listener for the specified event.

Properties

_captureListeners

Object protected

_item

LoadItem | Object private

Defined in _item:115

The LoadItem this loader represents. Note that this is null in a LoadQueue, but will be available on loaders such as XMLLoader and ImageLoader.

_listeners

Object protected

Inherited from EventDispatcher: _listeners:94

_loadItems

Null protected

Defined in _loadItems:155

A list of items that loaders load behind the scenes. This does not include the main item the loader is responsible for loading. Examples of loaders that have sub-items include the SpriteSheetLoader and ManifestLoader.

_preferXHR

Boolean private

Defined in _preferXHR:128

Whether the loader will try and load content using XHR (true) or HTML tags (false).

_rawResult

Object | String private

Defined in _rawResult:146

The loaded result before it is formatted. The rawResult is accessed using the GetResult method, and passing true.

_result

Object | String private

Defined in _result:136

The loaded result after it is formatted by an optional ResultFormatter. For items that are not formatted, this will be the same as the _rawResult:property. The result is accessed using the GetResult method.

_tag

Object private

Defined in _tag:173

An HTML tag (or similar) that a loader may use to load HTML content, such as images, scripts, etc.

BINARY

String static

Defined in BINARY:205

Available since 0.6.0

The preload type for generic binary types. Note that images are loaded as binary files when using XHR.

Default: binary

canceled

Boolean

Defined in canceled:66

Determine if the loader was canceled. Canceled loads will not fire complete events. Note that this property is readonly, so LoadQueue queues should be closed using close instead.

Default: false

CSS

String static

Defined in CSS:215

Available since 0.6.0

The preload type for css files. CSS files are loaded using a <link> when loaded with XHR, or a <style> tag when loaded with tags.

Default: css

GET

String

Defined in GET:197

Defines a GET request, use for a method value when loading data.

Default: get

IMAGE

String static

Defined in IMAGE:226

Available since 0.6.0

The preload type for image files, usually png, gif, or jpg/jpeg. Images are loaded into an <image> tag.

Default: image

JAVASCRIPT

String static

Defined in JAVASCRIPT:236

Available since 0.6.0

The preload type for javascript files, usually with the "js" file extension. JavaScript files are loaded into a <script> tag.

Since version 0.4.1+, due to how tag-loaded scripts work, all JavaScript files are automatically injected into the body of the document to maintain parity between XHR and tag-loaded scripts. In version 0.4.0 and earlier, only tag-loaded scripts are injected.

Default: javascript

JSON

String static

Defined in JSON:251

Available since 0.6.0

The preload type for json files, usually with the "json" file extension. JSON data is loaded and parsed into a JavaScript object. Note that if a callback is present on the load item, the file will be loaded with JSONP, no matter what the LoadQueue/preferXHR:property property is set to, and the JSON must contain a matching wrapper function.

Default: json

JSONP

String static

Defined in JSONP:264

Available since 0.6.0

The preload type for jsonp files, usually with the "json" file extension. JSON data is loaded and parsed into a JavaScript object. You are required to pass a callback parameter that matches the function wrapper in the JSON. Note that JSONP will always be used if there is a callback present, no matter what the LoadQueue/preferXHR:property property is set to.

Default: jsonp

loaded

Boolean

Defined in loaded:57

If the loader has completed loading. This provides a quick check, but also ensures that the different approaches used for loading do not pile up resulting in more than one complete Event.

Default: false

MANIFEST

String static

Defined in MANIFEST:277

Available since 0.6.0

The preload type for json-based manifest files, usually with the "json" file extension. The JSON data is loaded and parsed into a JavaScript object. PreloadJS will then look for a "manifest" property in the JSON, which is an Array of files to load, following the same format as the loadManifest method. If a "callback" is specified on the manifest object, then it will be loaded using JSONP instead, regardless of what the LoadQueue/preferXHR:property property is set to.

Default: manifest

POST

String

Defined in POST:189

Defines a POST request, use for a method value when loading data.

Default: post

progress

Number

Defined in progress:76

The current load progress (percentage) for this item. This will be a number between 0 and 1.

Example

var queue = new createjs.LoadQueue();
queue.loadFile("largeImage.png");
queue.on("progress", function() {
    console.log("Progress:", queue.progress, event.progress);
});

Default: 0

resultFormatter

Function

Defined in resultFormatter:101

A formatter function that converts the loaded raw result into the final result. For example, the JSONLoader converts a string of text into a JavaScript object. Not all loaders have a resultFormatter, and this property can be overridden to provide custom formatting.

Optionally, a resultFormatter can return a callback function in cases where the formatting needs to be asynchronous, such as creating a new image.

Default: null

resultFormatter

Function

Defined in resultFormatter:650

Available since 0.6.0

A custom result formatter function, which is called just before a request dispatches its complete event. Most loader types already have an internal formatter, but this can be user-overridden for custom formatting. The formatted result will be available on Loaders using GetResult, and passing true.

SOUND

String static

Defined in SOUND:291

Available since 0.6.0

The preload type for sound files, usually mp3, ogg, or wav. When loading via tags, audio is loaded into an <audio> tag.

Default: sound

SPRITESHEET

String static

Defined in SPRITESHEET:313

Available since 0.6.0

The preload type for SpriteSheet files. SpriteSheet files are JSON files that contain string image paths.

Default: spritesheet

SVG

String static

Defined in SVG:323

Available since 0.6.0

The preload type for SVG files.

Default: svg

TEXT

String static

Defined in TEXT:333

Available since 0.6.0

The preload type for text files, which is also the default file type if the type can not be determined. Text is loaded as raw text.

Default: text

type

String

Defined in type:93

The type of item this loader will load. See AbstractLoader for a full list of supported types.

VIDEO

String static

Defined in VIDEO:302

Available since 0.6.0

The preload type for video files, usually mp4, ts, or ogg. When loading via tags, video is loaded into an <video> tag.

Default: video

XML

String static

Defined in XML:344

Available since 0.6.0

The preload type for xml files. XML is loaded into an XML document.

Default: xml

Events

complete

Defined in complete:370

Available since 0.3.0

The Event that is fired when the entire queue has been loaded.

Event Payload:

  • target Object

    The object that dispatched the event.

  • type String

    The event type.

error

Defined in error:378

Available since 0.3.0

The ErrorEvent that is fired when the loader encounters an error. If the error was encountered by a file, the event will contain the item that caused the error. Prior to version 0.6.0, this was just a regular Event.

fileerror

Defined in fileerror:386

Available since 0.6.0

The Event that is fired when the loader encounters an internal file load error. This enables loaders to maintain internal queues, and surface file load errors.

Event Payload:

  • target Object

    The object that dispatched the event.

  • type String

    The even type ("fileerror")

  • The LoadItem | Object

    item that encountered the error

fileload

Defined in fileload:396

Available since 0.6.0

The Event that is fired when a loader internally loads a file. This enables loaders such as ManifestLoader to maintain internal LoadQueues and notify when they have loaded a file. The LoadQueue class dispatches a slightly different fileload event.

Event Payload:

  • target Object

    The object that dispatched the event.

  • type String

    The event type ("fileload")

  • item Object

    The file item which was specified in the loadFile or loadManifest call. If only a string path or tag was specified, the object will contain that value as a src property.

  • result Object

    The HTML tag or parsed result of the loaded item.

  • rawResult Object

    The unprocessed result, usually the raw text or binary data before it is converted to a usable object.

initialize

Defined in initialize:413

The Event that is fired after the internal request is created, but before a load. This allows updates to the loader for specific loading needs, such as binary or XHR image loading.

Event Payload:

  • target Object

    The object that dispatched the event.

  • type String

    The event type ("initialize")

  • loader AbstractLoader

    The loader that has been initialized.

loadstart

Defined in loadstart:362

Available since 0.3.1

The Event that is fired when a load starts.

Event Payload:

  • target Object

    The object that dispatched the event.

  • type String

    The event type.

progress

Defined in progress:355

Available since 0.3.0

The ProgressEvent that is fired when the overall progress changes. Prior to version 0.6.0, this was just a regular Event.