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

Manages the massive loading of the files by priority. The files with the highest priority will be loaded first. By default, all the files with the higher priority will be loaded before the files with a lower one start being loaded (loadByPriority value).

To sort the files by priority, the PriorityMassLoader will use a ArrayHeap object as filesQueue data structure.

View the examples

See also

CompositeMassLoader


Public Properties
 PropertyDefined By
 InheritedalwaysDispatchProgressEvent : 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
 InheritedbytesLoaded : uint
[read-only] Defines the bytes that have been loaded.
MassLoader
 InheritedbytesTotal : uint
[read-only] Defines the total bytes to load.
MassLoader
 InheritedcloseEvent : Event
[read-only] Defines the event that happend to close the MassLoader (Event.CLOSE or Event.COMPLETE).
MassLoader
  currentPriority : int
[read-only] Defines the current priority of the files that are being loaded.
PriorityMassLoader
  defaultPriority : int = 0
Defines the default priority to use for the addFile method.
PriorityMassLoader
 InheriteddispatchGlobalEvents : Boolean
Defines if the global events must be dispatched or not.
GlobalEventDispatcher
  loadByPriority : Boolean
Defines if the loading is done by priority.
PriorityMassLoader
 Inheritedloaded : Boolean
[read-only] Defines if the ILoadManager operation is complete.
MassLoader
 InheritedloadInfo : ILoadInfo
[read-only] Defines the ILoadInfo object linked to the IMassLoader.
MassLoader
 InheritedloadPolicy : ILoadPolicy
Defines the ILoadPolicy to use.
MassLoader
 InheritednextFileToLoad : ILoadManager
[read-only] Defines the next file that will be extracted from the queue to be loaded.
MassLoader
 InheritednumFiles : uint
[read-only] Defines the total of the files in the MassLoader.
MassLoader
 InheritednumFilesLoaded : uint
[read-only] Defines the number of files loaded.
MassLoader
 InheritednumFilesLoading : uint
[read-only] Defines the number of files being currently loaded.
MassLoader
 InheritednumFilesOpen : uint
[read-only] Defines the number of files being currently open.
MassLoader
 InheritednumFilesToLoad : uint
[read-only] Defines the number of files to load.
MassLoader
 InheritedparallelFiles : uint
Defines the number of files that will be loaded simultaneously.
MassLoader
 InheritedstateIdle : Boolean
[read-only] Defines if the MassLoader is idle.
MassLoader
 InheritedstateLoading : Boolean
[read-only] Defines if the MassLoader is loading.
MassLoader
Protected Properties
 PropertyDefined By
 Inheritedfiles : IList
[read-only] Defines all the files that must be loaded.
MassLoader
 InheritedfilesLoading : IList
[read-only] Defines the files that are currently being loaded.
MassLoader
 InheritedfilesQueue : IDataStructure
Defines the data structure to use for the file enqueuing.
MassLoader
Public Methods
 MethodDefined By
  
PriorityMassLoader(parallelFiles:uint = 0, loadByPriority:Boolean = false)
Creates a new PriorityMassLoader object.
PriorityMassLoader
  
Add the specified file in the loading queue with the default priority.
PriorityMassLoader
  
addPrioritizedFile(file:ILoadManager, priority:int = 0):void
Add a file with a specific priority in the loading queue.
PriorityMassLoader
  
clear():void
Clear the loading queues and files priorities.
PriorityMassLoader
 Inherited
dispatchEvent(evt:Event):Boolean
Dispatches the specified Event through the listeners.
GlobalEventDispatcher
 Inherited
Get the number of files to be loaded.
MassLoader
  
Retreives the priority of a ILoadManager object.
PriorityMassLoader
 Inherited
getFiles():Array
Get the files that will be loaded.
MassLoader
  
getFilesAtPriority(priority:int):Array
Defines the files to be loaded at the specified priority.
PriorityMassLoader
 Inherited
Retrieves the static index of the specified ILoadManager.
MassLoader
 Inherited
hasFile(file:ILoadManager):Boolean
Retrieves if a file is contained in the loading queue.
MassLoader
  
Removes the specified file from the loading queue.
PriorityMassLoader
  
setFilePriority(file:ILoadManager, priority:int):void
Set a file priority of a ILoadManager object.
PriorityMassLoader
 Inherited
start():Boolean
Starts downloading data from the specified ILoadManager objects.
MassLoader
 Inherited
stop():void
Stops the load operation in progress.
MassLoader
  
toString():String
Lists all the files contained in this PriorityMassLoader in a String.
PriorityMassLoader
Protected Methods
 MethodDefined By
  
createMassLoadEvent(file:ILoadManager, type:String, evt:Event = null):MassLoadEvent
Creates a MassLoadEvent based on the specified ILoadManager.
PriorityMassLoader
 Inherited
Retrieves the index of a file in the loading queue (if the loading of the specified file has been started).
MassLoader
 Inherited
isComplete():Boolean
Defines if the massive loading is complete.
MassLoader
 Inherited
loadFile(file:ILoadManager):Boolean
Start the loading of a file.
MassLoader
 Inherited
Start the loading of the next file.
MassLoader
 Inherited
onClose(evt:Event):void
Event.CLOSE listener.
MassLoader
 Inherited
onComplete(evt:Event):void
Event.COMPLETE listener.
MassLoader
 Inherited
onIOError(evt:IOErrorEvent):void
IOErrorEvent.IO_ERROR listener.
MassLoader
 Inherited
onOpen(evt:Event):void
Event.OPEN listener.
MassLoader
 Inherited
onProgress(evt:ProgressEvent):void
ProgressEvent.PROGRESS listener.
MassLoader
 Inherited
onSecurityError(evt:SecurityErrorEvent):void
SecurityError.SECURITY_ERROR listener.
MassLoader
 Inherited
Processes the loading policy on the currently closed file.
MassLoader
 Inherited
Process the loading policy on the currently file that is being open.
MassLoader
 Inherited
Register the MassLoader to the specified ILoadManager object's events.
MassLoader
  
Determines which file must be loaded first.
PriorityMassLoader
  
Start the loading of the files.
PriorityMassLoader
 Inherited
Unregister the MassLoader from the specified ILoadManager object's events.
MassLoader
 Inherited
Updates the bytesLoaded and bytesTotal values.
MassLoader
Events
 Event Summary Defined By
 InheritedDispatched when the download operation stops.MassLoader
 InheritedDispatched after all the data is received.MassLoader
 InheritedDispatched when the loading of a ILoadManager is closed (eg when the loading is complete or an error has occured).MassLoader
 InheritedDispatched when the MassLoader starts the loading of a file.MassLoader
 InheritedDispatched when the loading of a ILoadManager progresses.MassLoader
 InheritedDispatched after an event is dispatched.GlobalEventDispatcher
 InheritedDispatched before an event is dispatched.GlobalEventDispatcher
 InheritedDispatched when the download operation commences following a call to the MassLoader.start() method.MassLoader
  Dispatched when the loading of files with a lower priority starts.PriorityMassLoader
 InheritedDispatched when data is received as the download operation progresses.MassLoader
Property Detail
currentPriorityproperty
currentPriority:int  [read-only]

Defines the current priority of the files that are being loaded.


Implementation
    public function get currentPriority():int
defaultPriorityproperty 
public var defaultPriority:int = 0

Defines the default priority to use for the addFile method.

See also

loadByPriorityproperty 
loadByPriority:Boolean  [read-write]

Defines if the loading is done by priority. By default, this value is false.

If this value is false then the files will be loaded directly in the priority order but will not take care of the change of the priority. If this value is true, then the parallelFiles value will not be used.

If this value is changed after some files have been added to the loading queue, the order won't be the same as they were added (data structure updated)


Implementation
    public function get loadByPriority():Boolean
    public function set loadByPriority(value:Boolean):void

See also

Constructor Detail
PriorityMassLoader()Constructor
public function PriorityMassLoader(parallelFiles:uint = 0, loadByPriority:Boolean = false)

Creates a new PriorityMassLoader object.

Parameters
parallelFiles:uint (default = 0) — Defines how many file to load at the same time. This value will affect the loading only if the loadByPriority property is false.
 
loadByPriority:Boolean (default = false) — Defines if the PriorityMassLoader must load the files by priority. If this value is true, then the parallelFiles property will be ignored.
Method Detail
addFile()method
override public function addFile(file:ILoadManager):void

Add the specified file in the loading queue with the default priority.

Parameters

file:ILoadManager — The ILoadManager.

See also

addPrioritizedFile()method 
public function addPrioritizedFile(file:ILoadManager, priority:int = 0):void

Add a file with a specific priority in the loading queue.

Parameters

file:ILoadManager — The ILoadManager.
 
priority:int (default = 0) — The priority of the file.

clear()method 
override public function clear():void

Clear the loading queues and files priorities.

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

Creates a MassLoadEvent based on the specified ILoadManager. This method also add the priority to the MassLoadEvent.

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.
getFilePriority()method 
public function getFilePriority(file:ILoadManager):int

Retreives the priority of a ILoadManager object.

Parameters

file:ILoadManager — The file to get the priority.

Returns
int — The priority or 0 if the file isn't in the loading queue.

See also

getFilesAtPriority()method 
public function getFilesAtPriority(priority:int):Array

Defines the files to be loaded at the specified priority.

Parameters

priority:int — The priority.

Returns
Array — The files that will be loaded at the specified priority.
removeFile()method 
override public function removeFile(file:ILoadManager):void

Removes the specified file from the loading queue.

Parameters

file:ILoadManager — The ILoadManager.

setFilePriority()method 
public function setFilePriority(file:ILoadManager, priority:int):void

Set a file priority of a ILoadManager object. Note that changing the priority of a file if the PriorityMassLoader is already loading won't affect it.

Parameters

file:ILoadManager — The file to set the priority.
 
priority:int — The new priority of the file.


Throws
IllegalOperationError If — the file is not in the loading queue.
sortFiles()method 
protected function sortFiles(a:ILoadManager, b:ILoadManager):int

Determines which file must be loaded first. This method will return 0 if one of both arguments is not a ILoadableFile, otherwise it retrieves the priority value from the properties and compare them.

Parameters

a:ILoadManager — A ILoadManager.
 
b:ILoadManager — A ILoadManager.

Returns
int — An int greater than 0 if b must be loaded before a.

See also

startLoading()method 
override protected function startLoading():void

Start the loading of the files.

If the loadByPriority value is true, then, the method will retrieves the next file, checks his priority and start the loading of all the files with the same one. In that case, a PriorityEvent.PRIORITY_CHANGED event will be dispatched. If the loadByPriority value is false, it will retrieves the files by priority and start the loading of the value specified in the parallelFiles property.

If there is file currently being loaded or the filesQueue is empty, this method does nothing.

See also

toString()method 
override public function toString():String

Lists all the files contained in this PriorityMassLoader in a String.

Returns
String — A String containing all the files.
Event Detail
priorityChanged Event
Event Object Type: ch.capi.events.PriorityEvent
PriorityEvent.type property = ch.capi.events.PriorityEvent.PRIORITY_CHANGED

Dispatched when the loading of files with a lower priority starts. This event will be dispatched only if the value of loadByPriority is true.

Event when the priority changes.

See also

Examples
     var lf:LoadableFileFactory = new LoadableFileFactory();
     var file1:ILoadableFile = lf.create("myFile.txt");
     var file2:ILoadableFile = lf.create("myAnim.swf");
     var file3:ILoadableFile = lf.create("otherFile.xml");
     
     var ml:PriorityMassLoader = new PriorityMassLoader();
     ml.addPriorizedFile(file1, 15);
     ml.addPriorizedFile(file2, 15);
     ml.addFile(file3); //priority of 0 by default
     
     var eventFile:Function = function(evt:MassLoadEvent):void
     {
        var src:ILoadableFile = (evt.file as ILoadableFile);
        trace(evt.type+" => "+src);
     }
     ml.addEventListener(MassLoadEvent.FILE_OPEN, eventFile);
     ml.addEventListener(MassLoadEvent.FILE_CLOSE, eventFile);
     
     ml.start();