Packagech.capi.net.policies
Classpublic class DefaultLoadPolicy
InheritanceDefaultLoadPolicy Inheritance Object
Implements ILoadPolicy

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.

View the examples



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 = 1, continueOnFailure:Boolean = true)
Creates a new DefaultLoadPolicy object.
DefaultLoadPolicy
  
Retrieves how many times a file has been loaded.
DefaultLoadPolicy
  
processFileClose(file:ILoadManager, closeEvent:Event, source:IMassLoader):ILoadManager
Called by the MassLoader when a file download is complete.
DefaultLoadPolicy
  
Called by a IMassLoader before it starts to load the specified ILoadManager.
DefaultLoadPolicy
Property Detail
canContinueproperty
canContinue:Boolean  [read-only]

Defines if the massive loading can continue or not when a download has failed. This property will only be checked after the processFileClose() method has been called and only if it returns null.


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 = 1, continueOnFailure:Boolean = true)

Creates a new DefaultLoadPolicy object.

Parameters
reloadTimes:uint (default = 1) — 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).
processFileClose()method 
public function processFileClose(file:ILoadManager, closeEvent:Event, source:IMassLoader):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.
 
source:IMassLoader — The IMassLoader processing the ILoadManager.

Returns
ILoadManager — The ILoadManager to reload or null if there is nothing do.
processFileOpen()method 
public function processFileOpen(file:ILoadManager, source:IMassLoader):ILoadManager

Called by a IMassLoader before it starts to load the specified ILoadManager. If this method returns null, then the IMassLoader will simply skip the file. This method simply return the specified ILoadManager.

Parameters

file:ILoadManager — The ILoadManager before being started.
 
source:IMassLoader — The IMassLoader processing the ILoadManager.

Returns
ILoadManager — The ILoadManager to load or null if the IMassLoader must skip The file.
Examples
     var lp:DefaultLoadPolicy = new DefaultLoadPolicy(2);
     var ml:MassLoader = new MassLoader(0, true, lp);
     
     //...
     
     ml.start();