Packagech.capi.net
Classpublic class MassLoader
InheritanceMassLoader Inheritance flash.events.EventDispatcher
ImplementsIMassLoader
SubclassesPriorityMassLoader

This is a basic implementation of a IMassLoader object. The files will be loaded into the order of they have been added into the loading queue. In order to create some ILoadableFile, use the LoadableFileFactory class. If you want to specify some priority to the loaded files, check the PriorityMassLoader class.

It is important to note that the files won't be stored anymore after they have been completely loaded. You should have anoter reference to the created ILoadManager objects to access them and prevent that the Garbage Collector destroy them.


Example
Basic usage (limited verbose code) :
  var cl:CompositeMassLoader = new CompositeMassLoader();
  cl.addFile("myFile.txt");
  cl.addFile("myAnim.swf");
  
  var ml:IMassLoader = cl.massLoader;
  var eventFile:Function = function(evt:MassLoadEvent):void
  {
     var src:ILoadableFile = (evt.file as ILoadableFile);
     trace(evt.type+" => "+src.urlRequest.url);
  }
  ml.addEventListener(MassLoadEvent.FILE_OPEN, eventFile);
  ml.addEventListener(MassLoadEvent.FILE_CLOSE, eventFile);
  
  var onMassLoadComplete:Function = function(evt:Event):void
  {
     trace("massload complete");
  }
  ml.addEventListener(Event.COMPLETE, onMassLoadComplete);
  
  cl.start();
  //ml.start() also works
  
Advanced usage :
  var lf:LoadableFileFactory = new LoadableFileFactory();
  var file1:ILoadableFile = lf.create("myFile.txt");
  var file2:ILoadableFile = lf.create("myAnim.swf");
  
  var ml:MassLoader = new MassLoader();
  ml.addFile(file1);
  ml.addFile(file2);
  
  var eventFile:Function = function(evt:MassLoadEvent):void
  {
     var src:ILoadableFile = (evt.file as ILoadableFile);
     trace(evt.type+" => "+src.urlRequest.url);
  }
  ml.addEventListener(MassLoadEvent.FILE_OPEN, eventFile);
  ml.addEventListener(MassLoadEvent.FILE_CLOSE, eventFile);
  
  var onMassLoadComplete:Function = function(evt:Event):void
  {
     trace("massload complete");
  }
  ml.addEventListener(Event.COMPLETE, onMassLoadComplete);
  
  ml.start();
  

See also

LoadableFileFactory
CompositeMassLoader
PriorityMassLoader


Public Properties
 PropertyDefined by
  alwaysDispatchProgressEvent : Boolean = false
Defines if the progress event should be dispatched each time or only when all the number of specified parallel files are being loaded.
MassLoader
  bytesLoaded : uint
[read-only] Defines the bytes that have been loaded.
MassLoader
  bytesTotal : uint
[read-only] Defines the total bytes to load.
MassLoader
  closeEvent : Event
[read-only] Defines the event that happend to close the file (Event.CLOSE, Event.COMPLETE, ...).
MassLoader
  loadInfo : ILoadInfo
[read-only] Defines the ILoadInfo object linked to the IMassLoader.
MassLoader
  loadPolicy : ILoadPolicy
Defines the ILoadPolicy to use.
MassLoader
  nextFileToLoad : ILoadManager
[read-only] Defines the next file that will be extracted from the queue to be loaded.
MassLoader
  numFilesLoading : uint
[read-only] Defines the number of files being currently loaded.
MassLoader
  parallelFiles : uint
Defines the number of files that will be loaded simultaneously.
MassLoader
  stateIdle : Boolean
[read-only] Defines if the MassLoader is idle.
MassLoader
  stateLoading : Boolean
[read-only] Defines if the MassLoader is loading.
MassLoader
  useCache : Boolean
Defines if the MassLoader can use the cache or not.
MassLoader
Protected Properties
 PropertyDefined by
  files : IList
[read-only] Defines all the files that must be loaded.
MassLoader
  filesLoading : IList
[read-only] Defines the files that are currently being loaded.
MassLoader
  filesQueue : IDataStructure
Defines the data structure to use for the file enqueuing.
MassLoader
Public Methods
 MethodDefined by
  
MassLoader(parallelFiles:uint = 0, useCache:Boolean = true, loadPolicy:ILoadPolicy = null)
Creates a new MassLoader object.
MassLoader
  
addFile(file:ILoadManager):void
Add a file to the loading queue.
MassLoader
  
clear():void
Empty the loading queue.
MassLoader
  
getFileCount():uint
Get the number of files to be loaded.
MassLoader
  
getFiles():Array
Get the files that will be loaded.
MassLoader
  
hasFile(file:ILoadManager):Boolean
Retrieves if a file is contained into the loading queue.
MassLoader
  
Removes a file from the loading queue.
MassLoader
  
start():void
Starts downloading data from the specified ILoadableFile objects.
MassLoader
  
stop():void
Stops the load operation in progress.
MassLoader
  
toString():String
Lists all the files contained into this MassLoader into a String.
MassLoader
Protected Methods
 MethodDefined by
  
isComplete():Boolean
Defines if the massive loading is complete.
MassLoader
  
loadFile(file:ILoadManager):Boolean
Start the loading of a file.
MassLoader
  
Start the loading of the next file.
MassLoader
  
onClose(evt:Event):void
Event.CLOSE listener.
MassLoader
  
onComplete(evt:Event):void
Event.COMPLETE listener.
MassLoader
  
onIOError(evt:IOErrorEvent):void
IOErrorEvent.IO_ERROR listener.
MassLoader
  
onOpen(evt:Event):void
Event.OPEN listener.
MassLoader
  
onProgress(evt:ProgressEvent):void
ProgressEvent.PROGRESS listener.
MassLoader
  
onSecurityError(evt:SecurityErrorEvent):void
SecurityError.SECURITY_ERROR listener.
MassLoader
  
processPolicy(file:ILoadManager, closeEvent:Event):ILoadManager
Processes the loading policy on the currently closed file.
MassLoader
  
Register the MassLoader to the specified ILoadManager object's events.
MassLoader
  
startLoading():void
Start the loading of the files.
MassLoader
  
Unregister the MassLoader from the specified ILoadManager object's events.
MassLoader
  
updateBytes():void
Updates the bytesLoaded and bytesTotal values.
MassLoader
Events
 EventSummaryDefined by
   Dispatched when the download operation stops.MassLoader
   Dispatched after all the data is received.MassLoader
   Dispatched when the loading of a ILoadManager is closed (eg when the loading is complete or an error has occured).MassLoader
   Dispatched when the MassLoader starts the loading of a file.MassLoader
   Dispatched when the download operation commences following a call to the MassLoader.load() method.MassLoader
   Dispatched when data is received as the download operation progresses.MassLoader
Property detail
alwaysDispatchProgressEventproperty
public var alwaysDispatchProgressEvent:Boolean = false

Defines if the progress event should be dispatched each time or only when all the number of specified parallel files are being loaded.

bytesLoadedproperty 
bytesLoaded:uint  [read-only]

Defines the bytes that have been loaded.

Implementation
    public function get bytesLoaded():uint
bytesTotalproperty 
bytesTotal:uint  [read-only]

Defines the total bytes to load.

Implementation
    public function get bytesTotal():uint
closeEventproperty 
closeEvent:Event  [read-only]

Defines the event that happend to close the file (Event.CLOSE, Event.COMPLETE, ...).

Implementation
    public function get closeEvent():Event
filesproperty 
files:IList  [read-only]

Defines all the files that must be loaded.

Note that a file can be in the files list and not in the queue list. It means that the file is currently being loaded. After being loaded, the file is totally removed from the MassLoader.

Implementation
    protected function get files():IList
filesLoadingproperty 
filesLoading:IList  [read-only]

Defines the files that are currently being loaded. This list conaints only the files that dispatches the Event.OPEN event.

Implementation
    protected function get filesLoading():IList

See also

filesQueueproperty 
filesQueue:IDataStructure  [read-write]

Defines the data structure to use for the file enqueuing. By default, a QueueList is used. The MassLoader will use this IDataStructure to retrieves the next file to load. All the objects contained into the list must implement the ILoadManager interface.

Implementation
    protected function get filesQueue():IDataStructure
    protected function set filesQueue(value:IDataStructure):void

See also

loadInfoproperty 
loadInfo:ILoadInfo  [read-only]

Defines the ILoadInfo object linked to the IMassLoader.

Implementation
    public function get loadInfo():ILoadInfo
loadPolicyproperty 
loadPolicy:ILoadPolicy  [read-write]

Defines the ILoadPolicy to use. If the specified ILoadPolicy returns a ILoadManager, then the loaded bytes of the current file are decremented from the bytesLoaded and bytesTotal properties !

Implementation
    public function get loadPolicy():ILoadPolicy
    public function set loadPolicy(value:ILoadPolicy):void
nextFileToLoadproperty 
nextFileToLoad:ILoadManager  [read-only]

Defines the next file that will be extracted from the queue to be loaded.

Implementation
    public function get nextFileToLoad():ILoadManager
numFilesLoadingproperty 
numFilesLoading:uint  [read-only]

Defines the number of files being currently loaded. This value does not take care if the Event.OPEN event of each file has been launched. It is based on the MassLoadEvent.FILE_OPEN event.

Implementation
    public function get numFilesLoading():uint
parallelFilesproperty 
parallelFiles:uint  [read-write]

Defines the number of files that will be loaded simultaneously. If the value is changed during a load process, this won't affect it.

Implementation
    public function get parallelFiles():uint
    public function set parallelFiles(value:uint):void
stateIdleproperty 
stateIdle:Boolean  [read-only]

Defines if the MassLoader is idle.

Implementation
    public function get stateIdle():Boolean
stateLoadingproperty 
stateLoading:Boolean  [read-only]

Defines if the MassLoader is loading.

Implementation
    public function get stateLoading():Boolean
useCacheproperty 
useCache:Boolean  [read-write]

Defines if the MassLoader can use the cache or not. Note that if this property is set to false, it will override all the other ILoadManager.useCache value and reload them.

Implementation
    public function get useCache():Boolean
    public function set useCache(value:Boolean):void
Constructor detail
MassLoader()constructor
public function MassLoader(parallelFiles:uint = 0, useCache:Boolean = true, loadPolicy:ILoadPolicy = null)

Creates a new MassLoader object.

Parameters
parallelFiles:uint (default = 0) — The number of files to be loaded simultaneously.
 
useCache:Boolean (default = true) — Defines if the MassLoader must use the static cache or not.
 
loadPolicy:ILoadPolicy (default = null) — The ILoadPolicy to use.
Method detail
addFile()method
public function addFile(file:ILoadManager):void

Add a file to the loading queue. A file added while the MassLoader is already running will not be added to the current loading queue. You should stop and restart the MassLoader in order to include the file into the loading.

Parameters
file:ILoadManager — The file to add.

Throws
— If the file is already into the loading queue.

See also

clear()method 
public function clear():void

Empty the loading queue. This will not affect the current loading.

getFileCount()method 
public function getFileCount():uint

Get the number of files to be loaded.

Returns
uint — The number of file to load.
getFiles()method 
public function getFiles():Array

Get the files that will be loaded.

Returns
Array — An Array containing the files to load.
hasFile()method 
public function hasFile(file:ILoadManager):Boolean

Retrieves if a file is contained into the loading queue.

Parameters
file:ILoadManager — The ILoadManager.

Returns
Booleantrue if the file is into the loading queue.
isComplete()method 
protected function isComplete():Boolean

Defines if the massive loading is complete. This method will return true if there is no more file into the loading queue and there is currently no file loading.

Returns
Booleantrue if all the files are loaded.

See also

loadFile()method 
protected final function loadFile(file:ILoadManager):Boolean

Start the loading of a file. The file specified will not be removed from the loading queue !

Parameters
file:ILoadManager — The ILoadManager to load.

Returns
Booleantrue if the loading has been started.
loadNextFile()method 
protected function loadNextFile():ILoadManager

Start the loading of the next file. If there is no more file to load, then a null value is returned. Before the next file is being loaded, it is removed from the loading queue.

Returns
ILoadManager — The ILoadManager object being loaded or null.
onClose()method 
protected final function onClose(evt:Event):void

Event.CLOSE listener.

Parameters
evt:Event — The event object.
onComplete()method 
protected final function onComplete(evt:Event):void

Event.COMPLETE listener.

Parameters
evt:Event — The event object.
onIOError()method 
protected final function onIOError(evt:IOErrorEvent):void

IOErrorEvent.IO_ERROR listener.

Parameters
evt:IOErrorEvent — The event object.
onOpen()method 
protected final function onOpen(evt:Event):void

Event.OPEN listener. If the MassLoader has not been closed, the current file being open will be added to the filesLoading list.

Parameters
evt:Event — The event object.
onProgress()method 
protected final function onProgress(evt:ProgressEvent):void

ProgressEvent.PROGRESS listener.

Parameters
evt:ProgressEvent — The event object.
onSecurityError()method 
protected final function onSecurityError(evt:SecurityErrorEvent):void

SecurityError.SECURITY_ERROR listener.

Parameters
evt:SecurityErrorEvent — The event object.
processPolicy()method 
protected function processPolicy(file:ILoadManager, closeEvent:Event):ILoadManager

Processes the loading policy on the currently closed file.

Parameters
file:ILoadManager — The ILoadManager just closed.
 
closeEvent:Event — The event that occured.

Returns
ILoadManager — The ILoadManager that must be reloaded or null.
registerTo()method 
protected function registerTo(file:ILoadManager):void

Register the MassLoader to the specified ILoadManager object's events.

Parameters
file:ILoadManager — The file to register to.

See also

removeFile()method 
public function removeFile(file:ILoadManager):void

Removes a file from the loading queue.

Parameters
file:ILoadManager — The file to remove.

Throws
— If the file is not into the loading queue.

See also

start()method 
public final function start():void

Starts downloading data from the specified ILoadableFile objects.


Throws
— If the MassLoader is already loading.
startLoading()method 
protected function startLoading():void

Start the loading of the files. This method will launch the loading of the files (using the loadNextFile() method). The number of loading launched is determined by the parallelFiles value.

See also

stop()method 
public final function stop():void

Stops the load operation in progress. Any load operation in progress is immediately terminated.


Throws
— If the MassLoader is not loading.
toString()method 
public override function toString():String

Lists all the files contained into this MassLoader into a String.

Returns
String — A String containing all the files.
unregisterFrom()method 
protected function unregisterFrom(file:ILoadManager):void

Unregister the MassLoader from the specified ILoadManager object's events.

Parameters
file:ILoadManager — The file to unregister from.

See also

updateBytes()method 
protected final function updateBytes():void

Updates the bytesLoaded and bytesTotal values.

Event detail
closeevent 
Event object type: flash.events.Event

Dispatched when the download operation stops. This is following a call to the MassLoader.stop() method.

completeevent  
Event object type: flash.events.Event

Dispatched after all the data is received.

fileCloseevent  
Event object type: ch.capi.events.MassLoadEvent

Dispatched when the loading of a ILoadManager is closed (eg when the loading is complete or an error has occured).

fileOpenevent  
Event object type: ch.capi.events.MassLoadEvent

Dispatched when the MassLoader starts the loading of a file. This event is dispatched just before the ILoadManager.start() method is called.

openevent  
Event object type: flash.events.Event

Dispatched when the download operation commences following a call to the MassLoader.load() method.

progressevent  
Event object type: flash.events.ProgressEvent

Dispatched when data is received as the download operation progresses. The bytesTotal and bytesLoaded value are based on the overall progressing of the files stored into the loading queue. If the bytesTotal of a ILoadableFile has not been retrieved, then the virtualBytesTotal value will be used.