Packagech.capi.net
Classpublic class MassLoader
InheritanceMassLoader Inheritance GlobalEventDispatcher Inheritance flash.events.EventDispatcher
Implements IMassLoader
Subclasses PriorityMassLoader

This is a basic implementation of a IMassLoader object. The files will be loaded in the order of they have been added in the loading queue (FIFO). 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 another reference to the created ILoadManager instances to access them and prevent them to be destroyed by the Garbage Collector.

See also

ILoadPolicy
LoadableFileFactory
CompositeMassLoader
PriorityMassLoader


Public Properties
 PropertyDefined By
  alwaysDispatchProgressEvent : Boolean = true
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 MassLoader (Event.CLOSE or Event.COMPLETE).
MassLoader
 InheriteddispatchGlobalEvents : Boolean
Defines if the global events must be dispatched or not.
GlobalEventDispatcher
  loaded : Boolean
[read-only] Defines if the ILoadManager operation is 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
  numFiles : uint
[read-only] Defines the total of the files in the MassLoader.
MassLoader
  numFilesLoaded : uint
[read-only] Defines the number of files loaded.
MassLoader
  numFilesLoading : uint
[read-only] Defines the number of files being currently loaded.
MassLoader
  numFilesOpen : uint
[read-only] Defines the number of files being currently open.
MassLoader
  numFilesToLoad : uint
[read-only] Defines the number of files to load.
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
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 = 1)
Creates a new MassLoader object.
MassLoader
  
Add a file to the loading queue.
MassLoader
  
clear():void
Resets the MassLoader data.
MassLoader
 Inherited
dispatchEvent(evt:Event):Boolean
Dispatches the specified Event through the listeners.
GlobalEventDispatcher
  
Get the number of files to be loaded.
MassLoader
  
getFiles():Array
Get the files that will be loaded.
MassLoader
  
Retrieves the static index of the specified ILoadManager.
MassLoader
  
hasFile(file:ILoadManager):Boolean
Retrieves if a file is contained in the loading queue.
MassLoader
  
Removes a file from the loading queue.
MassLoader
  
start():Boolean
Starts downloading data from the specified ILoadManager objects.
MassLoader
  
stop():void
Stops the load operation in progress.
MassLoader
  
toString():String
Lists all the files contained in this MassLoader in a String.
MassLoader
Protected Methods
 MethodDefined By
  
createMassLoadEvent(file:ILoadManager, type:String, evt:Event = null):MassLoadEvent
Creates a MassLoadEvent based on the specified ILoadManager.
MassLoader
  
Retrieves the index of a file in the loading queue (if the loading of the specified file has been started).
MassLoader
  
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
  
Processes the loading policy on the currently closed file.
MassLoader
  
Process the loading policy on the currently file that is being open.
MassLoader
  
Register the MassLoader to the specified ILoadManager object's events.
MassLoader
  
Start the loading of the files.
MassLoader
  
Unregister the MassLoader from the specified ILoadManager object's events.
MassLoader
  
Updates the bytesLoaded and bytesTotal values.
MassLoader
Events
 Event Summary Defined 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 loading of a ILoadManager progresses.MassLoader
 InheritedDispatched after an event is dispatched.GlobalEventDispatcher
 InheritedDispatched before an event is dispatched.GlobalEventDispatcher
  Dispatched when the download operation commences following a call to the MassLoader.start() method.MassLoader
  Dispatched when data is received as the download operation progresses.MassLoader
Property Detail
alwaysDispatchProgressEventproperty
public var alwaysDispatchProgressEvent:Boolean = true

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 MassLoader (Event.CLOSE or Event.COMPLETE). This value is null if the MassLoader has not be started or is currently loading files.


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 in the list must implement the ILoadManager interface.


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

See also

loadedproperty 
loaded:Boolean  [read-only]

Defines if the ILoadManager operation is complete. This value is true when all the files have been loaded (successfully or not).


Implementation
    public function get loaded():Boolean
loadInfoproperty 
loadInfo:ILoadInfo  [read-only]

Defines the ILoadInfo object linked to the IMassLoader. You can just trace this value if you want to have some useful information.


Implementation
    public function get loadInfo():ILoadInfo

Example
         function onLoadProgress(evt:ProgressEvent):void
         {
                 trace(evt.target.loadInfo);
         }
         
         myMassLoader.addEventListener(ProgressEvent.PROGRESS, onLoadProgress);
         
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
numFilesproperty 
numFiles:uint  [read-only]

Defines the total of the files in the MassLoader. This value will remain constant after the loading has been started event if files are added.


Implementation
    public function get numFiles():uint
numFilesLoadedproperty 
numFilesLoaded:uint  [read-only]

Defines the number of files loaded. This value contains also the files that have not been loaded successfully.


Implementation
    public function get numFilesLoaded():uint
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

See also

numFilesOpenproperty 
numFilesOpen:uint  [read-only]

Defines the number of files being currently open. This value is based on the files that have sent the Event.OPEN event.


Implementation
    public function get numFilesOpen():uint

See also

numFilesToLoadproperty 
numFilesToLoad:uint  [read-only]

Defines the number of files to load. Once a file start its loading, it is no considered in this value anymore.


Implementation
    public function get numFilesToLoad():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
Constructor Detail
MassLoader()Constructor
public function MassLoader(parallelFiles:uint = 1)

Creates a new MassLoader object.

Parameters
parallelFiles:uint (default = 1) — The number of files to be loaded simultaneously.
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 in the loading.

Parameters

file:ILoadManager — The file to add.


Throws
flash.errors:IllegalOperationError If — the file is already in the loading queue.

See also

clear()method 
public function clear():void

Resets the MassLoader data. This method will clear the index values and the current loading queue. The current files being loaded won't be affected.

createMassLoadEvent()method 
protected function createMassLoadEvent(file:ILoadManager, type:String, evt:Event = null):MassLoadEvent

Creates a MassLoadEvent based on the specified ILoadManager.

Parameters

file:ILoadManager — The ILoadManager.
 
type:String — The MassLoadEvent type. This value can be MassLoadEvent.FILE_OPEN or MassLoadEvent.FILE_CLOSE.
 
evt:Event (default = null) — The close event, if any.

Returns
MassLoadEvent — The created MassLoadEvent.
getFileCount()method 
public function getFileCount():uint

Get the number of files to be loaded.

Returns
uint — The number of file to load.
getFileQueueIndex()method 
protected function getFileQueueIndex(file:ILoadManager):int

Retrieves the index of a file in the loading queue (if the loading of the specified file has been started).

Parameters

file:ILoadManager — The ILoadManager.

Returns
int — The index in the loading queue or -1.
getFiles()method 
public function getFiles():Array

Get the files that will be loaded.

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

Retrieves the static index of the specified ILoadManager. This index is attached to the ILoadManager when it is added to the loading queue and won't change even if files are removed. In order to reset the static index list, you must call the clear() method.

Parameters

file:ILoadManager — The ILoadManager.

Returns
int — The static index of the file or -1 if the file is not in the loading queue.
hasFile()method 
public function hasFile(file:ILoadManager):Boolean

Retrieves if a file is contained in the loading queue.

Parameters

file:ILoadManager — The ILoadManager.

Returns
Booleantrue if the file is in 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 in 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 ! This method won't start the loading if the ILoadPolicy returns null.

Parameters

file:ILoadManager — The ILoadManager to load.

Returns
Booleantrue if the loading has been started.

See also

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.

processClosePolicy()method 
protected function processClosePolicy(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.
processOpenPolicy()method 
protected function processOpenPolicy(file:ILoadManager):ILoadManager

Process the loading policy on the currently file that is being open. At this point, the file hasn't been open and isn't registered in the MassLoader.

Parameters

file:ILoadManager — The ILoadManager that must be loaded.

Returns
ILoadManager — The ILoadManager that must be loaded or null if the specified ILoadManager shouldn't be loaded.
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
flash.errors:IllegalOperationError If — the file is not in the loading queue.

See also

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

Starts downloading data from the specified ILoadManager objects.

Returns
Booleantrue if there is any file in the loading queue, false otherwise. In any cases, the events Event.OPEN and Event.COMPLETE will be dispatched.

Throws
flash.errors:IllegalOperationError 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
flash.errors:IllegalOperationError If — the MassLoader is not loading.
toString()method 
override public function toString():String

Lists all the files contained in this MassLoader in 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
close Event
Event Object Type: flash.events.Event
Event.type property = flash.events.Event.CLOSE

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

complete Event  
Event Object Type: flash.events.Event
Event.type property = flash.events.Event.COMPLETE

Dispatched after all the data is received.

fileClose Event  
Event Object Type: ch.capi.events.MassLoadEvent
MassLoadEvent.type property = ch.capi.events.MassLoadEvent.FILE_CLOSE

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

Event when the loading of a file stops.
fileOpen Event  
Event Object Type: ch.capi.events.MassLoadEvent
MassLoadEvent.type property = ch.capi.events.MassLoadEvent.FILE_OPEN

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

Event when the loading of a file starts.
fileProgress Event  
Event Object Type: ch.capi.events.MassLoadEvent
MassLoadEvent.type property = ch.capi.events.MassLoadEvent.FILE_PROGRESS

Dispatched when the loading of a ILoadManager progresses. This is just an encapsulation of the global ProgressEvent.PROGRESS event of the MassLoader.

Event when the loading of a file progresses.
open Event  
Event Object Type: flash.events.Event
Event.type property = flash.events.Event.OPEN

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

progress Event  
Event Object Type: flash.events.ProgressEvent
ProgressEvent.type property = flash.events.ProgressEvent.PROGRESS

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 in the loading queue. If the bytesTotal of a ILoadableFile has not been retrieved, then the virtualBytesTotal value will be used.