PreloadJS

PreloadJS  0.1.0

PreloadJS > PreloadJS > PreloadJS
Search:
 
Filters

Class PreloadJS - extends AbstractLoader

PreloadJS provides a consistent way to preload content for use in HTML applications.

Constructor

PreloadJS ( Boolean )
Parameters:
Boolean <object> useXHR2 Determines whether the preload instance will use XmlHttpRequests, or fall back on tag loading.

Properties

CSS - static String

The preload type for css files.
Default Value: css

IMAGE - static String

The preload type for image files, usually png, gif, or jpg/jpeg
Default Value: image

JAVASCRIPT - static String

The preload type for javascript files, usually with the "js" file extension.
Default Value: javascript

JSON - static String

The preload type for json files, usually with the "json" file extension.
Default Value: json

maintainScriptOrder - Boolean

Ensure loaded scripts "complete" in the order they are specified.
Default Value: true

next - PreloadJS

The next preload queue to process when this one is complete.
Default Value: null

SOUND - static String

The preload type for sound files, usually mp3, ogg, or wav.
Default Value: sound

stopOnError - Boolean

Stop processing the current queue when an error is encountered.
Default Value: false

TEXT - static String

The preload type for text files, which is also the default file type if the type can not be determined.
Default Value: text

TIMEOUT_TIME - static Number

Time in millseconds to assume a load has failed.
Default Value: 8000

useXHR - Boolean

Use XMLHttpRequest when possible.
Default Value: true

XML - static String

The preload type for xml files.
Default Value: xml

Properties inherited from AbstractLoader:

Methods

close

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

To stop and restart a queue, use the setPaused(true|false) method instead.
Returns: void

getResult

Object getResult ( value )
Lookup a loaded item using either the "id" or "src" that was specified when loading it.
Parameters:
value <String> The "id" or "src" of the loaded item.
Returns: Object
A result object containing the contents of the object that was initially requested using loadFile or loadManifest, including:
  1. src: The source of the file that was requested.
  2. type: The type of file that was loaded. If it was not specified, this is auto-detected by PreloadJS using the file extension.
  3. id: The id of the loaded object. If it was not specified, the ID will be the same as the "src" property.
  4. data: Any arbitrary data that was specified, otherwise it will be undefined.
  5. result: The loaded object. PreloadJS provides usable tag elements when possible:
    • An HTMLImageElement tag (<image />) for images
    • An HTMLAudioElement tag (<audio >) for audio
    • A script tag for JavaScript (<script></script>)
    • A style tag for CSS (<style></style>)
    • Raw text for JSON or any other kind of loaded item
This object is also returned via the "onFileLoad" callback, although a "target" will be included, which is a reference to the PreloadJS instance.

initialize

void initialize ( useXHR )
Initialize a PreloadJS instance
Parameters:
useXHR <object> Use XHR for loading (vs tag/script loading)
Returns: void

installPlugin

void installPlugin ( plugin )
Register a plugin. Plugins can map to both load types (sound, image, etc), or can map to specific extensions (png, mp3, etc). Only one plugin can currently exist per suffix/type. Plugins must return an object containing: callback: The function to call types: An array of types to handle extensions: An array of extensions to handle. This is overriden by type handlers
Parameters:
plugin <Function> The plugin to install
Returns: void

load

void load ( )
Begin loading the queued items.
Returns: void

loadFile

void loadFile ( file , loadNow )
Load a single file. Note that calling loadFile appends to the current queue, so it can be used multiple times to add files. Use loadManifest() to add multiple files at onces. To clear the queue first use the close() method.
Parameters:
file <Object | String> The file object or path to load. A file can be either
  1. a path to a resource (string). Note that this kind of load item will be converted to an object (next item) in the background.
  2. OR an object that contains:
    • src: The source of the file that is being loaded. This property is required. The source can either be a string (recommended), or an HTML tag.
    • type: The type of file that will be loaded (image, sound, json, etc). PreloadJS does auto-detection of types using the extension. Supported types are defined on PreloadJS, such as PreloadJS.IMAGE. It is recommended that a type is specified when a non-standard file URI (such as a php script) us used.
    • id: A string indentifier which can be used to reference the loaded object.
    • data: An arbitrary data object, which is included with the loaded object
loadNow <Boolean> Kick off an immediate load (true) or wait for a load call (false). The default value is true. If the queue is paused, and this value is true, the queue will resume.
Returns: void

loadManifest

void loadManifest ( manifest , loadNow )
Load a manifest. This is a shortcut method to load a group of files. To load a single file, use the loadFile method. Note that calling loadManifest appends to the current queue, so it can be used multiple times to add files. To clear the queue first, use the close() method.
Parameters:
manifest <Array> The list of files to load. Each file can be either
  1. a path to a resource (string). Note that this kind of load item will be converted to an object (next item) in the background.
  2. OR an object that contains:
    • src: The source of the file that is being loaded. This property is required. The source can either be a string (recommended), or an HTML tag.
    • type: The type of file that will be loaded (image, sound, json, etc). PreloadJS does auto-detection of types using the extension. Supported types are defined on PreloadJS, such as PreloadJS.IMAGE. It is recommended that a type is specified when a non-standard file URI (such as a php script) us used.
    • id: A string indentifier which can be used to reference the loaded object.
    • data: An arbitrary data object, which is included with the loaded object
loadNow <Boolean> Kick off an immediate load (true) or wait for a load call (false). The default value is true. If the queue is paused, and this value is true, the queue will resume.
Returns: void

setMaxConnections

void setMaxConnections ( value )
Set the maximum number of concurrent connections.
Parameters:
value <Number> The number of concurrent loads to allow. By default, only a single connection is open at any time. Note that browsers and servers may have a built-in maximum number of open connections
Returns: void

setPaused

void setPaused ( value )
Pause or resume the current load. The active item will not cancel, but the next items in the queue will not be processed.
Parameters:
value <Boolean> Whether the queue should be paused or not.
Returns: void

Methods inherited from AbstractLoader: