Packagech.capi.net
Classpublic class PriorityMassLoader
InheritancePriorityMassLoader Inheritance MassLoader Inheritance flash.events.EventDispatcher
ImplementsIMassLoader
SubclassesApplicationMassLoader

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 priority will start being loaded (loadByPriority value).

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


Example
  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.urlRequest.url);
  }
  ml.addEventListener(MassLoadEvent.FILE_OPEN, eventFile);
  ml.addEventListener(MassLoadEvent.FILE_CLOSE, eventFile);
  
  ml.start();
  

See also

CompositePriorityMassLoader
ArrayHeap


Public Properties
 PropertyDefined by
 InheritedalwaysDispatchProgressEvent : 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
 InheritedbytesLoaded : uint
Defines the bytes that have been loaded.
MassLoader
 InheritedbytesTotal : uint
Defines the total bytes to load.
MassLoader
 InheritedcloseEvent : Event
Defines the event that happend to close the file (Event.CLOSE, 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
  loadByPriority : Boolean = true
Defines if the loading is done by priority.
PriorityMassLoader
 InheritedloadInfo : ILoadInfo
Defines the ILoadInfo object linked to the IMassLoader.
MassLoader
 InheritedloadPolicy : ILoadPolicy
Defines the ILoadPolicy to use.
MassLoader
 InheritednextFileToLoad : ILoadManager
Defines the next file that will be extracted from the queue to be loaded.
MassLoader
 InheritednumFilesLoading : uint
Defines the number of files being currently loaded.
MassLoader
 InheritedparallelFiles : uint
Defines the number of files that will be loaded simultaneously.
MassLoader
 InheritedstateIdle : Boolean
Defines if the MassLoader is idle.
MassLoader
 InheritedstateLoading : Boolean
Defines if the MassLoader is loading.
MassLoader
 InheriteduseCache : Boolean
Defines if the MassLoader can use the cache or not.
MassLoader
Protected Properties
 PropertyDefined by
 Inheritedfiles : IList
Defines all the files that must be loaded.
MassLoader
 InheritedfilesLoading : IList
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
  
Creates a new PriorityMassLoader object.
PriorityMassLoader
  
addFile(file:ILoadManager):void
Add the specified file into the loading queue with the specified defaultPriority.
PriorityMassLoader
  
addPrioritizedFile(file:ILoadManager, priority:int = 0):void
Add a file with a specific priority into the loading queue.
PriorityMassLoader
 Inherited
clear():void
Empty the loading queue.
MassLoader
 Inherited
getFileCount():uint
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
 Inherited
hasFile(file:ILoadManager):Boolean
Retrieves if a file is contained into the loading queue.
MassLoader
  
Removes the specified file from the loading queue.
PriorityMassLoader
 Inherited
start():void
Starts downloading data from the specified ILoadableFile objects.
MassLoader
 Inherited
stop():void
Stops the load operation in progress.
MassLoader
  
toString():String
Lists all the files contained into this PriorityMassLoader into a String.
PriorityMassLoader
Protected Methods
 MethodDefined by
 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
processPolicy(file:ILoadManager, closeEvent:Event):ILoadManager
Processes the loading policy on the currently closed file.
MassLoader
 Inherited
Register the MassLoader to the specified ILoadManager object's events.
MassLoader
  
Determines which file must be loaded first.
PriorityMassLoader
  
startLoading():void
Start the loading of the files.
PriorityMassLoader
 Inherited
Unregister the MassLoader from the specified ILoadManager object's events.
MassLoader
 Inherited
updateBytes():void
Updates the bytesLoaded and bytesTotal values.
MassLoader
Events
 EventSummaryDefined by
 Inherited Dispatched when the download operation stops.MassLoader
 Inherited Dispatched after all the data is received.MassLoader
 Inherited Dispatched when the loading of a ILoadManager is closed (eg when the loading is complete or an error has occured).MassLoader
 Inherited Dispatched when the MassLoader starts the loading of a file.MassLoader
 Inherited Dispatched when the download operation commences following a call to the MassLoader.load() method.MassLoader
   Dispatched when the loading of files with a lower priority starts.PriorityMassLoader
 Inherited Dispatched 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 
public var loadByPriority:Boolean = true

Defines if the loading is done by priority. If this value is false then the files will be loaded directly into 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.

Constructor detail
PriorityMassLoader()constructor
public function PriorityMassLoader()

Creates a new PriorityMassLoader object.

Method detail
addFile()method
public override function addFile(file:ILoadManager):void

Add the specified file into the loading queue with the specified defaultPriority. To specify the file priority manually, use the addPriorizedFile method.

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 into the loading queue.

Parameters
file:ILoadManager — The ILoadManager.
 
priority:int (default = 0) — The priority of the file.
getFilePriority()method 
public function getFilePriority(file:ILoadManager):int

Retreives the priority of a ILoadManager object. In order to change the priority of a file, simple remove it and readd it using the addPriorizedFile method.

Parameters
file:ILoadManager — The file to get the priority.

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

See also

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

Removes the specified file from the loading queue.

Parameters
file:ILoadManager — The ILoadManager.
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 
protected override 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 into the parallelFiles property.

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

See also

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

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

Returns
String — A String containing all the files.
Event detail
priorityChangedevent 
Event object type: ch.capi.events.PriorityEvent

Dispatched when the loading of files with a lower priority starts. This event won't be dispatched if the value of loadByPriority is false.

See also