Preload.Preload Class
Preload class is object utility for preload different file format.
Constructor
Preload.Preload
()
Item Index
Properties
Methods
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.
getResult
-
value
Lookup a loaded item using either the "id" or "src" that was specified when loading it.
Parameters:
-
value
StringThe "id" or "src" of the loaded item.
Returns:
src
: The source of the file that was requested.- type: The type of file that was loaded. If it was not specified, this is auto-detected by Preload using the file extension.
id
: The id of the loaded object. If it was not specified, the ID will be the same as the "src" property.- data: Any arbitrary data that was specified, otherwise it will be undefined.
result
: The loaded object. Preload 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
- An HTMLImageElement tag (
load
()
Begin loading the queued items.
loadFile
-
file
-
[loadNow=true]
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 | StringThe file object or path to load. A file can be either
- a path to a resource (string). Note that this kind of load item will be converted to an object (next item) in the background.
- 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). Preload does auto-detection of types using the extension. Supported types are defined on Preload, such as Preload.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 identifier which can be used to reference the loaded object.
- data: An arbitrary data object, which is included with the loaded object
-
[loadNow=true]
Boolean optionalKick off an immediate load (true) or wait for a load call (false). If the queue is paused, and this value is true, the queue will resume.
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
ArrayThe list of files to load. Each file can be either
- a path to a resource (string). Note that this kind of load item will be converted to an object (next item) in the background.
- 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). Preload does auto-detection of types using the extension. Supported types are defined on Preload, such as Preload.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 identifier which can be used to reference the loaded object.
- data: An arbitrary data object, which is included with the loaded object
-
loadNow
BooleanKick 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.
setMaxConnections
-
value
Set the maximum number of concurrent connections.
Parameters:
-
value
NumberThe 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
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
BooleanWhether the queue should be paused or not.
Properties
CSS
String
static
The preload type for css files.
Default: css
IMAGE
String
static
The preload type for image files, usually png, gif, or jpg/jpeg
Default: image
JSON
String
static
The preload type for json files, usually with the "json" file extension.
Default: json
loaded
Boolean
Determine if this loader has completed already.
Default: false
next
Preload
The next preload queue to process when this one is complete.
Default: null
progress
Number
The current load progress (percentage) for this item.
Default: 0
SOUND
String
static
The preload type for sound files, usually mp3, ogg, or wav.
Default: sound
TEXT
String
static
The preload type for text files, which is also the default file type if the type can not be determined.
Default: text
TIMEOUT_TIME
Number
static
Time in millseconds to assume a load has failed.
Default: 8000
XML
String
static
The preload type for xml files.
Default: xml
Events
onComplete
The callback to fire when all loading is complete.
onError
The callback to fire when the loader encounters an error. If the error was encountered by a file, the event will contain the required file data, but the target will be the loader.
onFileLoad
The callback to fire when a file completes.
onFileProgress
The callback to fire when a file progress changes.
onLoadStart
The callback to fire when a load starts.
onProgress
The callback to fire when progress changes.