LoadGroup

Kind of class:class
Inherits from:EventDispatcher < CoreObject
Implements:
Version:06/08/07
Author:Aaron Clinger
Classpath:org.casalib.load.LoadGroup
File last modified:Monday, 01 December 2008, 13:34:40
Allows multiple loads to be treated as one larger load item.
Example:
  • var xmlLoad:XmlLoad = new XmlLoad("test.xml");
    var imageLoad:MediaLoad = new MediaLoad(this.loadZone_mc, "test.jpg");
    
    var myLoadGroup = new LoadGroup();
    this.myLoadGroup.addLoad(this.xmlLoad);
    this.myLoadGroup.addLoad(this.imageLoad);
    this.myLoadGroup.addEventObserver(this, LoadGroup.EVENT_LOAD_PERCENT, "onGroupLoadPercent");
    this.myLoadGroup.addEventObserver(this, LoadGroup.EVENT_LOAD_ERROR, "onGroupLoadError");
    
    function onGroupLoadPercent(sender:LoadGroup, progress:Percent):Void {
        trace("My group is " + progress.getPercentage() + "% loaded.");
    }
    
    function onGroupLoadError(sender:LoadGroup, failedLoad:BytesLoadInterface):Void {
        this.myLoadGroup.removeLoad(failedLoad);
        this.myLoadGroup.start();
    }
    
    this.myLoadGroup.start();
Events broadcasted to listeners:
  • onLoadStart = function (sender:LoadGroup) {}
  • onLoadStop = function (sender:LoadGroup) {}
  • onLoadComplete = function (sender:LoadGroup) {}
  • onLoadPercent = function (sender:LoadGroup, progress:Percent) {}
  • onLoadError = function (sender:LoadGroup, failedLoad:BytesLoadInterface) {}

Summary


Constructor
Class properties
Instance methods
  • addLoad (loadItem:BytesLoadInterface) : Void
    • Add a load item to the group.
  • removeLoad (loadItem:BytesLoadInterface) : Boolean
    • Removes a load item from the group.
  • getLoads : Array
  • start : Void
    • Starts the group load process and begins reporting of the total load percentage of all files to observers.
  • stop : Void
    • Stops the group load process.
  • hasLoaded : Boolean
    • Determines whether the requested file has finished loading.
  • isLoading : Boolean
    • Determines whether the requested file is in the process of loading.
  • destroy : Void
    • Removes any internal variables, intervals, enter frames, internal MovieClips and event observers to allow the object to be garbage collected.

Constructor

LoadGroup

function LoadGroup (
)

Creates a new LoadGroup object.

Class properties

EVENT_LOAD_COMPLETE

static EVENT_LOAD_COMPLETE:String = 'onLoadComplete'
(read,write)

EVENT_LOAD_ERROR

static EVENT_LOAD_ERROR:String = 'onLoadError'
(read,write)

EVENT_LOAD_PERCENT

static EVENT_LOAD_PERCENT:String = 'onLoadPercent'
(read,write)

EVENT_LOAD_START

static EVENT_LOAD_START:String = 'onLoadStart'
(read,write)

EVENT_LOAD_STOP

static EVENT_LOAD_STOP:String = 'onLoadStop'
(read,write)

Instance methods

addLoad

function addLoad (
loadItem:BytesLoadInterface, percentOfGroup:Percent) : Void

Add a load item to the group.
Parameters:
loadItem :
Load to be added to the load group. Can be any class that implements org.casalib.load.base.BytesLoadInterface and dispatches events "onLoadProgress", "onLoadComplete" and "onLoadError".
percentOfGroup:
[optional] Defines the percentage of the total group the size of the load item represents; defaults to equal increments.

destroy

function destroy (
) : Void

Removes any internal variables, intervals, enter frames, internal MovieClips and event observers to allow the object to be garbage collected.

Always call
var xmlLoad:XmlLoad = new XmlLoad("test.xml");
var imageLoad:MediaLoad = new MediaLoad(this.loadZone_mc, "test.jpg");

var myLoadGroup = new LoadGroup();
this.myLoadGroup.addLoad(this.xmlLoad);
this.myLoadGroup.addLoad(this.imageLoad);
this.myLoadGroup.addEventObserver(this, LoadGroup.EVENT_LOAD_PERCENT, "onGroupLoadPercent");
this.myLoadGroup.addEventObserver(this, LoadGroup.EVENT_LOAD_ERROR, "onGroupLoadError");

function onGroupLoadPercent(sender:LoadGroup, progress:Percent):Void {
    trace("My group is " + progress.getPercentage() + "% loaded.");
}

function onGroupLoadError(sender:LoadGroup, failedLoad:BytesLoadInterface):Void {
    this.myLoadGroup.removeLoad(failedLoad);
    this.myLoadGroup.start();
}

this.myLoadGroup.start();
before deleting last object pointer.
#

getLoads

function getLoads (
) : Array

Returns:
  • Returns an Array contains all load items in the LoadGroup.

hasLoaded

function hasLoaded (
) : Boolean

Determines whether the requested file has finished loading.
#
Returns:
  • Returns
    var xmlLoad:XmlLoad = new XmlLoad("test.xml");
    var imageLoad:MediaLoad = new MediaLoad(this.loadZone_mc, "test.jpg");
    
    var myLoadGroup = new LoadGroup();
    this.myLoadGroup.addLoad(this.xmlLoad);
    this.myLoadGroup.addLoad(this.imageLoad);
    this.myLoadGroup.addEventObserver(this, LoadGroup.EVENT_LOAD_PERCENT, "onGroupLoadPercent");
    this.myLoadGroup.addEventObserver(this, LoadGroup.EVENT_LOAD_ERROR, "onGroupLoadError");
    
    function onGroupLoadPercent(sender:LoadGroup, progress:Percent):Void {
        trace("My group is " + progress.getPercentage() + "% loaded.");
    }
    
    function onGroupLoadError(sender:LoadGroup, failedLoad:BytesLoadInterface):Void {
        this.myLoadGroup.removeLoad(failedLoad);
        this.myLoadGroup.start();
    }
    
    this.myLoadGroup.start();
    if file has completely loaded; otherwise "onLoadProgress".
    #

isLoading

function isLoading (
) : Boolean

Determines whether the requested file is in the process of loading.
#
Returns:
  • Returns "onLoadComplete" if the file is currently loading; otherwise "onLoadError".
    #

removeLoad

function removeLoad (
loadItem:BytesLoadInterface) : Boolean

Removes a load item from the group.
Parameters:
loadItem:
Load to be removed from the load group.
Returns:
  • Returns true if item was successfully found and removed; otherwise false.
Usage note:
  • You cannot remove a load item when the LoadGroup is in the process of loading.

start

function start (
) : Void

Starts the group load process and begins reporting of the total load percentage of all files to observers.
Events broadcasted to listeners:
  • onLoadStart = function (sender:LoadGroup) {}

stop

function stop (
) : Void

Stops the group load process.
Events broadcasted to listeners:
  • onLoadStop = function (sender:LoadGroup) {}