Packagech.capi.net
Classpublic class CompositeMassLoader
InheritanceCompositeMassLoader Inheritance GlobalEventDispatcher Inheritance flash.events.EventDispatcher
Implements ICompositeMassLoader

This is a utility class to avoid too much verbose code within the Masapi API. Note that this class simply uses the PriorityMassLoader and LoadableFileFactory to create the ILoadableFile and for the loading management. It is an encapsulation class to the Masapi API core functions. It is also a basic implementation of a ICompositeMassLoader.

The CompositeMassLoader keeps by default a reference to the created ILoadableFile (see the keepFiles property).

View the examples

See also

LoadableFileFactory
IMassLoader
CompositeMassLoaderRegisterer


Public Properties
 PropertyDefined By
 InheriteddispatchGlobalEvents : Boolean
Defines if the global events must be dispatched or not.
GlobalEventDispatcher
  keepFiles : Boolean
[read-only] Defines if the CompositeMassLoader must keep references on the created ILoadableFile instances.
CompositeMassLoader
  loadableFileFactory : LoadableFileFactory
Defines the LoadableFileFactory to use.
CompositeMassLoader
  massLoader : IMassLoader
[read-only] Defines the PriorityMassLoader to use.
CompositeMassLoader
  name : String
[read-only] Defines the name of the CompositeMassLoader.
CompositeMassLoader
Public Methods
 MethodDefined By
  
CompositeMassLoader(name:String = null, parallelFiles:int = 1, register:Boolean = true)
Creates a new CompositeMassLoader object.
CompositeMassLoader
  
addFile(fileOrURL:Object, fileType:String = null, priority:Function = null, onOpen:Function = null, onProgress:Function = null, onComplete:Function = null, onClose:Function = null, onIOError:Function = null, onSecurityError:* = null):ILoadableFile
Creates a ILoadableFile from a url and add it to the current loading queue.
CompositeMassLoader
  
clear(destroyAll:Boolean = true):void
Clears the loading queue of the IMassLoader and empty the references to the created ILoadableFile instances.
CompositeMassLoader
  
createFile(fileOrURL:Object, fileType:String = null, onOpen:Function = null, onProgress:Function = null, onComplete:Function = null, onClose:Function = null, onIOError:Function = null, onSecurityError:Function = null):ILoadableFile
Creates a ILoadableFile from a url.
CompositeMassLoader
 Inherited
dispatchEvent(evt:Event):Boolean
Dispatches the specified Event through the listeners.
GlobalEventDispatcher
  
Retrieves the ILoadableFile at the specified index.
CompositeMassLoader
  
getFileByProps(props:Object, strict:Boolean = false):ILoadableFile
Retrieves the first file that matches the specified properties.
CompositeMassLoader
  
Retrieves the number of ILoadableFile instances that have been stored.
CompositeMassLoader
  
getFiles():Array
Retrieves all the files created by the CompositeMassLoader.
CompositeMassLoader
  
getFilesByProps(props:Object, strict:Boolean = false):Array
Retrieves all the files that matche the specified properties.
CompositeMassLoader
  
start(noCache:Boolean = false):void
Starts the loading of the massive loader.
CompositeMassLoader
  
stop():void
Stops the loading of the massive loader.
CompositeMassLoader
Protected Methods
 MethodDefined By
  
createLoadableFile(request:URLRequest, fileType:String = null):ILoadableFile
Retrieves a ILoadableFile from a URLRequest and and a specified file type issued from the LoadableFileType constants.
CompositeMassLoader
  
eventRedirector(evt:Event):void
Redirects all the events that it received.
CompositeMassLoader
  
registerTo(massLoader:IMassLoader):void
Register as listener to the specified IMassLoader.
CompositeMassLoader
  
Stores the specified ILoadableFile.
CompositeMassLoader
  
unregisterFrom(massLoader:IMassLoader):void
Unregister from the specified IMassLoader.
CompositeMassLoader
Events
 Event Summary Defined By
  Dispatched when the download operation stops.CompositeMassLoader
  Dispatched after all the files have been downloaded, even if errors occured.CompositeMassLoader
  Dispatched when the loading of a ILoadManager is closed (eg when the loading is complete or an error has occured).CompositeMassLoader
  Dispatched when the MassLoader starts the loading of a file.CompositeMassLoader
  Dispatched when the loading of a ILoadManager progresses.CompositeMassLoader
 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.CompositeMassLoader
  Dispatched when the loading of files with a lower priority starts.CompositeMassLoader
  Dispatched when data is received as the download operation progresses.CompositeMassLoader
Property Detail
keepFilesproperty
keepFiles:Boolean  [read-only]

Defines if the CompositeMassLoader must keep references on the created ILoadableFile instances. If this is set to false, a reference must be kept on the ILoadableFile to prevent the Garbage Collector to delete them.


Implementation
    public function get keepFiles():Boolean

See also

loadableFileFactoryproperty 
loadableFileFactory:LoadableFileFactory  [read-write]

Defines the LoadableFileFactory to use.


Implementation
    public function get loadableFileFactory():LoadableFileFactory
    public function set loadableFileFactory(value:LoadableFileFactory):void
massLoaderproperty 
massLoader:IMassLoader  [read-only]

Defines the PriorityMassLoader to use.


Implementation
    public function get massLoader():IMassLoader
nameproperty 
name:String  [read-only]

Defines the name of the CompositeMassLoader. If the name is null, then the CompositeMassLoader is not registered in the global map.


Implementation
    public function get name():String

See also

Constructor Detail
CompositeMassLoader()Constructor
public function CompositeMassLoader(name:String = null, parallelFiles:int = 1, register:Boolean = true)

Creates a new CompositeMassLoader object.

Parameters
name:String (default = null) — The name of the CompositeMassLoader. That name must be unique. If no name is defined, then the instance won't be registered.
 
parallelFiles:int (default = 1) — The number of files to load at the same time.
 
register:Boolean (default = true) — Defines if the CompositeMassLoader must be automatically registered in the CompositeMassLoaderRegisterer class.
Method Detail
addFile()method
public function addFile(fileOrURL:Object, fileType:String = null, priority:Function = null, onOpen:Function = null, onProgress:Function = null, onComplete:Function = null, onClose:Function = null, onIOError:Function = null, onSecurityError:* = null):ILoadableFile

Creates a ILoadableFile from a url and add it to the current loading queue. If the fileOrURL parameter is an object, all the properties will be put in the ILoadableFile.properties attribute of the created ILoadableFile.

Parameters

fileOrURL:Object — The url of the file or an Object containing at least the 'url' attribute.
 
fileType:String (default = null) — The type of the file. If not defined and the fileOrURL parameter is an Object, then the type will be extracted from the attribute 'type'.
 
priority:Function (default = null) — The priority of the file (must be an int). If not defined and the fileOrURL parameter is an Object, then the priority of the file will be extracted from the attribute 'priority'. If no priority is specified, then the priority will be 0.
 
onOpen:Function (default = null) — The Event.OPEN listener.
 
onProgress:Function (default = null) — The ProgressEvent.PROGRESS listener.
 
onComplete:Function (default = null) — The Event.COMPLETE listener.
 
onClose:Function (default = null) — The Event.CLOSE listener.
 
onIOError:Function (default = null) — The IOErrorEvent.IO_ERROR listener.
 
onSecurityError:* (default = null) — The SecurityErrorEvent.SECURITY_ERROR listener.

Returns
ILoadableFile — The created ILoadableFile.

Throws
ArgumentError If fileOrURl is null.
 
ArgumentError If — the priority is invalid.

See also


Example
         var cm:CompositeMassLoader = new CompositeMassLoader(false);
         
         //those three lines have the same behavior
         cm.addFile("myAnimation.swf", LoadableFileType.BINARY, 10);
         cm.addFile({url:"myAnimation.swf", type:LoadableFileType.BINARY, priority:10});
         cm.addFile(new URLRequest("myAnimation.swf"), LoadableFileType.BINARY, 10);
         
clear()method 
public function clear(destroyAll:Boolean = true):void

Clears the loading queue of the IMassLoader and empty the references to the created ILoadableFile instances.

Parameters

destroyAll:Boolean (default = true) — If true, then the destroy() method will be called on all the ILoadableFile.

See also

createFile()method 
public function createFile(fileOrURL:Object, fileType:String = null, onOpen:Function = null, onProgress:Function = null, onComplete:Function = null, onClose:Function = null, onIOError:Function = null, onSecurityError:Function = null):ILoadableFile

Creates a ILoadableFile from a url. This method doesn't register the file to the IMassLoader but it stores it in the CompositeMassLoader. If the fileOrURL parameter is an object, all the properties will be put in the ILoadableFile.properties attribute of the created ILoadableFile.

Parameters

fileOrURL:Object — The url of the file or an Object containing at least the 'url' attribute.
 
fileType:String (default = null) — The type of the file. If not defined and the fileOrURL parameter is an Object, then the type will be extracted from the attribute 'type'.
 
onOpen:Function (default = null) — The Event.OPEN listener.
 
onProgress:Function (default = null) — The ProgressEvent.PROGRESS listener.
 
onComplete:Function (default = null) — The Event.COMPLETE listener.
 
onClose:Function (default = null) — The Event.CLOSE listener.
 
onIOError:Function (default = null) — The IOErrorEvent.IO_ERROR listener.
 
onSecurityError:Function (default = null) — The SecurityErrorEvent.SECURITY_ERROR listener.

Returns
ILoadableFile — The created ILoadableFile.

Throws
ArgumentError if — the fileOrURL parameter is not defined.

See also


Example
         var cm:CompositeMassLoader = new CompositeMassLoader(false);
         
         //those three lines have the same behavior
         cm.createFile("myAnimation.swf", LoadableFileType.BINARY);
         cm.createFile({url:"myAnimation.swf", type:LoadableFileType.BINARY});
         cm.createFile(new URLRequest("myAnimation.swf"), LoadableFileType.BINARY);
         
createLoadableFile()method 
protected function createLoadableFile(request:URLRequest, fileType:String = null):ILoadableFile

Retrieves a ILoadableFile from a URLRequest and and a specified file type issued from the LoadableFileType constants.

Parameters

request:URLRequest — The URLRequest.
 
fileType:String (default = null) — The type of the file.

Returns
ILoadableFile — The ILoadableFile created.

Throws
ArgumentError If — the fileType is not valid.

See also

eventRedirector()method 
protected function eventRedirector(evt:Event):void

Redirects all the events that it received. This method acts like a proxy : it is attached to a IMassLoader as event listener and all the events are redispatched through the CompositeMassLoader. Note that all the events are cloned before redirection.

Parameters

evt:Event — The Event object.

getFileAt()method 
public function getFileAt(index:uint):ILoadableFile

Retrieves the ILoadableFile at the specified index.

Parameters

index:uint — The index.

Returns
ILoadableFile — The ILoadableFile.
getFileByProps()method 
public function getFileByProps(props:Object, strict:Boolean = false):ILoadableFile

Retrieves the first file that matches the specified properties.

Parameters

props:Object — An Object containing the properties to match.
 
strict:Boolean (default = false) — Defines if the check must be strict or not.

Returns
ILoadableFile — The first ILoadableFile instance that matches the properties or null.

See also

getFileCount()method 
public function getFileCount():uint

Retrieves the number of ILoadableFile instances that have been stored.

Returns
uint — The number of stored ILoadableFile.
getFiles()method 
public function getFiles():Array

Retrieves all the files created by the CompositeMassLoader. Note that the CompositeMassLoader register the files only if the keepFiles property is set to true.

Returns
Array — The created ILoadableFile.
getFilesByProps()method 
public function getFilesByProps(props:Object, strict:Boolean = false):Array

Retrieves all the files that matche the specified properties.

Parameters

props:Object — An Object containing the properties to match.
 
strict:Boolean (default = false) — Defines if the check must be strict or not.

Returns
Array — An Array of ILoadableFile that match the specified properties.

See also

registerTo()method 
protected function registerTo(massLoader:IMassLoader):void

Register as listener to the specified IMassLoader.

Parameters

massLoader:IMassLoader — The IMassLoader to listen.

start()method 
public function start(noCache:Boolean = false):void

Starts the loading of the massive loader.

Parameters

noCache:Boolean (default = false) — If true, then all the files contained in this ICompositeMassLoader will be added back in the IMassLoader to be reloaded. This cache has nothing to do with the useCache property of a ILoadableFile. Moreover, this parameter will have an effect only if the keepFiles property is true.

See also

stop()method 
public function stop():void

Stops the loading of the massive loader.

See also

storeFile()method 
protected function storeFile(file:ILoadableFile):void

Stores the specified ILoadableFile.

Parameters

file:ILoadableFile — The file to store.

unregisterFrom()method 
protected function unregisterFrom(massLoader:IMassLoader):void

Unregister from the specified IMassLoader.

Parameters

massLoader:IMassLoader — The IMassLoader to stop to listen to.

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.

See also

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

Dispatched after all the files have been downloaded, even if errors occured.

See also

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.

See also

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.

See also

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.

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.

See also

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.

Event when the priority changes.

See also

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.

See also

Examples
The CompositeMassLoader keep a reference to the created files by default :
     var cm:CompositeMassLoader = new CompositeMassLoader();
     cm.addFile("myAnimation.swf");
     cm.addFile("otherSWF.swf", LoadableFileType.BINARY);
     cm.addFile({url:"otherSWF.swf", type:LoadableFileType.BINARY, priority:30});
     cm.addFile("myVariables.txt", LoadableFileType.TEXT, 10);
     
     cm.start();