Packagech.capi.net
Classpublic class DefaultLoadPolicy
ImplementsILoadPolicy

Basic implementation of a ILoadPolicy. This class manages the number of a file must be reloaded if its download fails.

The DefaultLoadPolicy uses weak references to store the files in order to know how many times the files have been reloaded.


Example
  var lp:DefaultLoadPolicy = new DefaultLoadPolicy(2);
  var ml:MassLoader = new MassLoader(0, true, lp);
  
  //...
  
  ml.start();
  



Public Properties
 PropertyDefined by
  canContinue : Boolean
[read-only] Defines if the massive loading can continue or not when a download has failed.
DefaultLoadPolicy
  continueOnFailure : Boolean
Defines if the massive loading can continue event if a file fails to be downloaded.
DefaultLoadPolicy
  defaultFiles : IMap
[read-only] Defines the IMap that links the loaded files within a default file to load if the specified file failed.
DefaultLoadPolicy
  reloadTimes : uint
Defines how many times a file must be reloaded if its download fails.
DefaultLoadPolicy
Public Methods
 MethodDefined by
  
DefaultLoadPolicy(reloadTimes:uint = 3, continueOnFailure:Boolean = true)
Creates a new DefaultLoadPolicy object.
DefaultLoadPolicy
  
Retrieves how many times a file has been loaded.
DefaultLoadPolicy
  
processFile(file:ILoadManager, closeEvent:Event):ILoadManager
Called by the MassLoader when a file download is complete.
DefaultLoadPolicy
Property detail
canContinueproperty
canContinue:Boolean  [read-only]

Defines if the massive loading can continue or not when a download has failed.

Implementation
    public function get canContinue():Boolean
continueOnFailureproperty 
public var continueOnFailure:Boolean

Defines if the massive loading can continue event if a file fails to be downloaded.

defaultFilesproperty 
defaultFiles:IMap  [read-only]

Defines the IMap that links the loaded files within a default file to load if the specified file failed. Note that this IMap uses weak references.

Implementation
    public function get defaultFiles():IMap

Example
   var lp:DefaultLoadPolicy = new DefaultLoadPolicy(2);
   var ml:MassLoader = new MassLoader(0, true, lp);
   
   var factory:LoadableFileFactory = new LoadableFileFactory();
   var baseFile:ILoadableFile = factory.create("foo.xml");
   var defaultFile:ILoadableFile = factory.create("fooDefault.xml");
   
   lp.defaultFiles.put(baseFile, defaultFile);
   
   ml.addFile(baseFile);
   ml.start();
   

reloadTimesproperty 
public var reloadTimes:uint

Defines how many times a file must be reloaded if its download fails. 0 means that the file will be reloaded since it is successfully loaded.

Constructor detail
DefaultLoadPolicy()constructor
public function DefaultLoadPolicy(reloadTimes:uint = 3, continueOnFailure:Boolean = true)

Creates a new DefaultLoadPolicy object.

Parameters
reloadTimes:uint (default = 3) — Defines how many times a file must be reloaded if its download fails. 0 means that the file will be reloaded since it is successfully loaded.
 
continueOnFailure:Boolean (default = true) — Defines if the massive loading can continue event if a file fails to be downlaoded.
Method detail
getFileLoadedTimes()method
public function getFileLoadedTimes(file:ILoadManager):uint

Retrieves how many times a file has been loaded.

Parameters
file:ILoadManager — The ILoadManager.

Returns
uint — The number of times that the file has been loaded (starts from 1).
processFile()method 
public function processFile(file:ILoadManager, closeEvent:Event):ILoadManager

Called by the MassLoader when a file download is complete. This can be due to a successful download or not (see the closeEvent parameters).

Parameters
file:ILoadManager — The ILoadManager to process.
 
closeEvent:Event — The event within the ILoadManager is finished.

Returns
ILoadManager — The ILoadManager to reload or null if there is nothing do.