SamplePlugin:38
A PreloadJS plugin provides a way to inject functionality into PreloadJS to load file types that are unsupported, or in a way that PreloadJS does not.
Note that this class is mainly for documentation purposes, and is not a real plugin.
Plugins are registered based on file extension, or supported preload types, which are defined as constants on the LoadQueue class. Available load types are:
A plugin defines what types or extensions it handles via a getPreloadHandlers method, which is called when a plugin is first registered.
To register a plugin with PreloadJS, simply install it into a LoadQueue before files begin to load using the installPlugin method:
var queue = new createjs.LoadQueue();
queue.installPlugin(createjs.SamplePlugin);
queue.loadFile("test.jpg");
The getPreloadHandlers method can also return a callback
property, which is a function that will be invoked before each file is loaded. Check out the preloadHandler
for more information on how the callback works. For example, the SoundJS plugin allows PreloadJS to manage a
download that uses the Flash Player.
fileLoadHandlerevent
Defined in
fileLoadHandler:186
This is a sample method to show a completeHandler, which is optionally specified by the return object in the
preloadHandler. This sample provides a completeHandler to the
LoadItem. This method is called after the item has completely loaded, but before
the fileload event is dispatched from the LoadQueue.
The provided sample also listens for the complete event on the loader it returns to show a different usage.
getPreloadHandlers
Defined in
getPreloadHandlers:83
When a plugin is installed, this method will be called to let PreloadJS know when to invoke the plugin.
PreloadJS expects this method to return an object containing:
Note that currently, PreloadJS only supports a single handler for each extension or file type.
// Check out the SamplePlugin source for a more complete example.
SamplePlugin.getPreloadHandlers = function() {
return {
callback: SamplePlugin.preloadHandler,
extensions: ["jpg", "jpeg", "png", "gif"]
}
}
If a plugin provides both "type" and "extension" handlers, the type handler will take priority, and will only fire once per file. For example if you have a handler for type=sound, and for extension=mp3, the callback will fire when it matches the type.
An object defining a callback, type handlers, and extension handlers (see description)
preloadHandlerloadItem
queue
Defined in
preloadHandler:124
This is a sample method to show how to handle the callback specified in the LoadQueue/getPreloadHandlers. Right before a file is loaded, if a plugin for the file type or extension is found, then the callback for that plugin will be invoked. This gives the plugin an opportunity to modify the load item, or even cancel the load. The return value of the callback determines how PreloadJS will handle the file:
Since the LoadItem is passed by reference, a plugin can modify as needed, even appending additional data to it. Note that if the src is modified, PreloadJS will automatically update the LoadItem/ext:property property.
// Cancel a load
SamplePlugin.preloadHandler = function(loadItem, queue) {
if (loadItem.id.indexOf("thumb") { return false; } // Don't load items like "image-thumb.png"
return true;
}
// Specify a completeHandler
SamplePlugin.preloadHandler = function(loadItem, queue) {
item.completeHandler = SamplePlugin.fileLoadHandler;
}
// Check out the SamplePlugin source to see another example.
Note: In 0.4.2 and earlier, instead of a LoadItem, arguments were passed in, and a modified object was returned to PreloadJS. This has been changed to passing a reference to the LoadItem, which can be directly modified.
How PreloadJS should handle the load. See the main description for more info.