Loader
| Kind of class: | class |
|---|---|
| Inherits from: | Dispatcher |
| Author: | Arthur Clemens, Martijn de Visser (rewritten for EventDispatcher usage and added check for already loaded data) |
| Classpath: | org.asapframework.util.loader.Loader |
| File last modified: | Wednesday, 11 October 2006, 21:56:59 |
Loads SWF movies or JPEG images into a clip.
Multiple/subsequent movies that are added are queued. Loader can deal with multiple loading threads simultaneously (but the real life efficiency is dependent on the capability of the browser).See also:
Example:
Example to load multiple images:
var loader:Loader = new Loader();Listen for feedback during loading:
loader.addEventListener(LoaderEvent.ON_PROGRESS, this); loader.addEventListener(LoaderEvent.ON_DONE, this);Load the assets. We will make them invisible first, and turn them visible once they are loaded:
loader.load( movieholder1_mc, "seaside.jpg", "Seaside", false ); loader.load( movieholder2_mc, "tree.jpg", "Woods", false );To keep track of loading progress, implement the listener method - we will update a progress bar with the incoming data:
private function onLoadProgress (e:LoaderEvent) : Void { progressbar._xscale = 100 / e.total * e.loaded; }And the method that is called when each asset has finished loading:
private function onLoadDone (e:LoaderEvent) : Void { trace(e.name + " is loaded"); e.targetClip._visible = true; // or use ActionQueue to fade in the clip }We could also have implemented LoaderEvent.ON_ALL_LOADED to find out when everything is done.
Events broadcast to listeners:
LoaderEvent with type:
LoaderEvent with type:
LoaderEvent with type:
LoaderEvent with type:
LoaderEvent with type:
ON_ALL_LOADED When no more assets are in the queueLoaderEvent with type:
ON_START When a new LoaderWorker starts loadingLoaderEvent with type:
ON_PROGRESS When some data has been receivedLoaderEvent with type:
ON_DONE When one asset has finished loadingLoaderEvent with type:
ON_ERROR When an error happened during loadingSummary
Constructor
Constructor
Loader
function Loader (
inThreadCount:Number)
Parameters:
inThreadCount:
(optional) The number of threads the Loader should be using. Default (when left empty) is 4. This means that (theoretically) 4 files will be loaded at once. The actual number that Flash uses is dependent on the browser. When the number of threads is 1, the next file will only be loaded when the first is done loading.
Instance methods
getFileCount
function getFileCount (
) : Number
getTotalAndLoaded
function getTotalAndLoaded (
) : Object
Calculates the total number of bytes loading and loaded of all workers.
Returns:
A value object {total:Number, loaded:Number}.
isLoading
function isLoading (
) : Boolean
The Loader's loading state.
Returns:
True when one of the workers is still loading, false when all workers have finished.
load
function load (
inLoc:MovieClip,
inUrl:String,
inName:String,
inIsVisible:Boolean) : Boolean
Adds a file to the load queue. The file will be ordered to load as soon as one of the loader workers is idle. Supported file types are: swf, jpg
Parameters:
loc :
Movieclip in where the file should be loaded
url :
File's url or disk location
name :
(optional) Unique identifying name for the loading request
isVisible:
(optional) The visible state of the movieclip once the file is loaded; if not specified, visible = true is assumed
Returns:
Error state; false if an error occurred, true if successfully added to the queue
pauseAllLoading
function pauseAllLoading (
) : Void
Stops the loading of all files until resumeAllLoading is called.
resumeAllLoading
function resumeAllLoading (
) : Void
Stops the loading of all files until resumeAllLoading is called.
stopAllLoading
function stopAllLoading (
) : Void
Stops the loading of all files, clears the loading queue and frees the loader workers.
stopLoading
function stopLoading (
inName:String) : Void
Stops the loading of one file.
Parameters:
name:
Name of the loading request as passed with load
toString
function toString (
) : String