API Documentation for: 0.4.0
Show:

AbstractLoader Class

Defined in: AbstractLoader:39
Module: PreloadJS

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

Methods

_dispatchEvent

(
  • eventObj
  • eventPhase
)
protected

Parameters:

_formatQueryString

(
  • data
  • [query]
)
private

Formats an object into a query string for either a POST or GET request.

Parameters:

  • data Object

    The data to convert to a query string.

  • [query] Array optional

    Existing name/value pairs to append on to this query.

_isCanceled

() Boolean protected

Defined in _isCanceled:296

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.

_parseURI

(
  • path
)
Array protected

Defined in _parseURI:310

Parse a file URI using the AbstractLoader.FILE_PATTERN RegExp pattern.

Parameters:

  • path String

    The file path to parse.

Returns:

Array:

The matched file contents. Please see the AbstractLoader.FILE_PATTERN property for details on the return value. This will return null if it does not match.

_sendComplete

() protected

Defined in _sendComplete:270

Dispatch a complete event. Please see the complete event for details on the event payload.

_sendError

(
  • event
)
protected

Defined in _sendError:281

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

Parameters:

  • event Object

    The event object containing specific error properties.

_sendLoadStart

() protected

Defined in _sendLoadStart:234

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

_sendProgress

(
  • value
)
protected

Defined in _sendProgress:245

Dispatch a progress event. Please see the progress event for details on the event payload.

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

(
  • src
  • [basePath]
  • [data]
)
String

Defined in buildPath:344

Available since 0.3.1

A utility method that builds a file path using a source, a basePath, and a data object, and formats it into a new path. All of the loaders in PreloadJS use this method to compile paths when loading.

Parameters:

  • src String

    The source path to add values to.

  • [basePath] String optional

    A string to prepend to the file path. Sources beginning with http:// or similar will not receive a base path.

  • [data] Object optional

    Object used to append values to this request as a query string. Existing parameters on the path will be preserved.

Returns:

String:

A formatted string that contains the path and the supplied parameters.

close

()

Defined in close:223

Close the active queue. Closing a queue completely empties the queue, and prevents any remaining items from starting to download. Note that currently any active loads will remain open, and events may be processed.

To stop and restart a queue, use the setPaused method instead.

dispatchEvent

(
  • eventObj
  • [target]
)
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.

  • [target] Object optional

    The object to use as the target property of the event object. This will default to the dispatching object. This parameter is deprecated and will be removed.

Returns:

Boolean:

Returns the value of eventObj.defaultPrevented.

hasEventListener

(
  • type
)
Boolean

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

Parameters:

  • type String

    The string type of the event.

Returns:

Boolean:

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

init

() private

Defined in init:204

Initialize the loader. This is called by the constructor.

initialize

() protected

Initialization method.

load

()

Defined in load:211

Begin loading the queued items. This method can be called when a LoadQueue is set up but not started immediately.

Example:

 var queue = new createjs.LoadQueue();
 queue.addEventListener("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:246

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:174

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.removeAllEvenListeners();

 // 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.

toString

() String

Inherited from EventDispatcher but overwritten in toString:383

Returns:

String:

a string representation of the instance.

Properties

_basePath

String private

Defined in _basePath:99

Available since 0.3.1

A path that will be prepended on to the item's source parameter before it is loaded.

_captureListeners

Object protected

_item

Object private

Defined in _item:90

The item this loader represents. Note that this is null in a LoadQueue, but will be available on loaders such as XHRLoader and TagLoader.

_listeners

Object protected

canceled

Boolean

Defined in canceled:72

Determine if the loader was canceled. Canceled loads will not fire complete events. Note that LoadQueue queues should be closed using close instead of canceled.

Default: false

FILE_PATTERN

RegExp protected static

Defined in FILE_PATTERN:53

The RegExp pattern to use to parse file URIs. This supports simple file names, as well as full domain URIs with query strings. The resulting match is: protocol:$1 domain:$2 path:$3 file:$4 extension:$5 query:$6.

loaded

Boolean

Defined in loaded:63

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

onComplete

Function deprecated

Defined in onComplete:166

Deprecated: Use addEventListener and the "complete" event.

REMOVED. Use addEventListener and the complete event.

onError

Function deprecated

Defined in onError:173

Deprecated: Use addEventListener and the "error" event.

REMOVED. Use addEventListener and the error event.

onLoadStart

Function deprecated

Defined in onLoadStart:159

Deprecated: Use addEventListener and the "loadstart" event.

REMOVED. Use addEventListener and the loadstart event.

onProgress

Function deprecated

Defined in onProgress:152

Deprecated: Use addEventListener and the "progress" event.

REMOVED. Use addEventListener and the progress event.

progress

Number

Defined in progress:82

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

Default: 0

Events

complete

Defined in complete:129

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:137

Available since 0.3.0

The event 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. There may be additional properties such as the error reason on event objects.

Event Payload:

  • target Object

    The object that dispatched the event.

  • type String

    The event type.

  • [item] Object optional

    The item that was being loaded that caused the error. The item 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 property.

  • [error] String optional

    The error object or text.

loadstart

Defined in loadstart:121

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:109

Available since 0.3.0

The event that is fired when the overall progress changes.

Event Payload:

  • target Object

    The object that dispatched the event.

  • type String

    The event type.

  • loaded Number

    The amount that has been loaded so far. Note that this is may just be a percentage of 1, since file sizes can not be determined before a load is kicked off, if at all.

  • total Number

    The total number of bytes. Note that this may just be 1.

  • progress Number

    The ratio that has been loaded between 0 and 1.