Packagebr.com.stimuli.loading
Classpublic class BulkLoader
InheritanceBulkLoader Inheritance flash.events.EventDispatcher

Manages loading for simultaneous items and multiple formats. Exposes a simpler interface, with callbacks instead of events for each item to be loaded (but still dispatched "global" events). The number of simultaneous connections is configurable.


Example
Basic usage:
    import br.com.stimuli.loading.BulkLoader;

    / /instantiate a BulkLoader with a name : a way to reference this instance from another classes without having to set a expolicit reference on many places
    var bulkLoader : BulkLoader = new BulkLoader("main loading");
    // add items to be loaded
    bulkLoader.add("my_xml_file.xml");
    bulkLoader.add("main.swf");
    // you can also use a URLRequest object
    var backgroundURL : URLRequest = new URLRequest("background.jpg");
    bulkLoader.add(backgroundURL);

    // add event listeners for the loader itself :
    // event fired when all items have been loaded
    bulkLoader.addEventListener(BulkLoader.COMPLETE, onCompleteHandler);
    // event fired when loading progress has been made:
    bulkLoader.addEventListener(BulkLoader.PROGRESS, _onProgressHandler);

    // start loading all items
    bulkLoader.start();

    function _onProgressHandler(evt : ProgressEvent) : void{
        trace("Loaded" , evt.bytesLoaded," of ",  evt.bytesTotal);
    }

    function onCompleteHandler(evt : ProgressEvent) : void{
            trace("All items are loaeded and ready to consume");
            // grab the main movie clip:
            var mainMovie : MovieClip = bulkLoader.getMovieClip("main.swf");
            // Get the xml object:
            var mXML : XML = bulkLoader.getXML("my_xml_file.xml");
            // grab the bitmap for the background image by a string:
            var myBitmap : Bitmap = bulkLoader.getBitmap("background.jpg");
            // grab the bitmap for the background image using the url rquest object:
            var myBitmap : Bitmap = bulkLoader.getBitmap(backgroundURL);
    }

    // In any other class you can access those assets without having to pass around references to the bulkLoader instance.
    // In another class  you get get a reference to the "main loading" bulkLoader:
    var mainLoader : BulkLoader = BulkLoader.getLoader("main loading");
    // now grab the xml:
    var mXML : XML = mainLoader.getXML("my_xml_file.xml");
    // or shorter:
    var mXML : XML = BulkLoader.getLoader("main loading").getXML("my_xml_file.xml");
       



Public Properties
 PropertyDefined by
  allowsAutoIDFromFileName : Boolean
Determines if an autmatic id created from the file name.
BulkLoader
  AVAILABLE_EXTENSIONS : Array
[static] List of all file extensions that the BulkLoader knows how to guess.
BulkLoader
  avgLatency : Number
The average latency (in miliseconds) for the entire loading.
BulkLoader
  bytesLoaded : int
[read-only] The sum of all bytesLoaded for each item.
BulkLoader
  bytesTotal : int
[read-only] The total bytes to load.
BulkLoader
  bytesTotalCurrent : int
[read-only] The sum of all bytes loaded so far.
BulkLoader
  contents : Object
[read-only] Returns an object where the urls are the keys(as strings) and the loaded contents are the value for that key.
BulkLoader
  highestPriority : int
[read-only] Returns the highest priority for all items in this BulkLoader instance.
BulkLoader
  id : int
[read-only] The id of this bulkLoader instance
BulkLoader
  IMAGE_EXTENSIONS : Array
[static] List of file extensions that will be automagically use a Loader object for loading.
BulkLoader
  isFinished : Boolean
[read-only]
BulkLoader
  isRunning : Boolean
[read-only] A boolean indicating if the instace has started and has not finished loading all items
BulkLoader
  items : Array
[read-only] Returns a copy of all LoadingItem in this intance.
BulkLoader
  itemsLoaded : int
Number of items alrealdy loaded.
BulkLoader
  itemsTotal : int
[read-only] Total number of items to load.
BulkLoader
  loadedRatio : Number
[read-only] The ratio (0->1) of items to load / items total.
BulkLoader
  logFunction : Function
The function to be used in logging.
BulkLoader
  MOVIECLIP_EXTENSIONS : Array
[static]
BulkLoader
  name : String
[read-only] The name by which this loader instance can be identified.
BulkLoader
  numConnections : int
[read-only] The number of simultaneous connections to use.
BulkLoader
  percentLoaded : Number
[read-only] The percentage (0->1) of bytes loaded.
BulkLoader
  SOUND_EXTENSIONS : Array
[static] List of file extensions that will be automagically treated as sound for loading.
BulkLoader
  speed : Number
[read-only]
BulkLoader
  speedAvg : Number
The average speed (in kb/s) for the entire loading.
BulkLoader
  stringSubstitutions : Object
The object, used as a hashed to substitute variables specified on the url used in add.
BulkLoader
  TEXT_EXTENSIONS : Array
[static] List of file extensions that will be automagically treated as text for loading.
BulkLoader
  totalTime : Number
Time in seconds for the whole loading.
BulkLoader
  totalWeight : int
[read-only] The sum of weights in all items to load.
BulkLoader
  VIDEO_EXTENSIONS : Array
[static] List of file extensions that will be automagically treated as video for loading.
BulkLoader
  weightPercent : Number
[read-only] The weighted percent of items loaded(0->1).
BulkLoader
  XML_EXTENSIONS : Array
[static]
BulkLoader
Public Methods
 MethodDefined by
  
BulkLoader(name:String, numConnections:int, logLevel:int)
Creates a new BulkLoader object identifiable by the name parameter.
BulkLoader
  
add(url:*, props:Object = null):LoadingItem
Adds a new assets to be loaded.
BulkLoader
  
changeItemPriority(key:String, newPriority:int):Boolean
Updates the priority of item identified by key with a new value, the queue will be re resorted right away.
BulkLoader
  
clear():void
Removes this instance from the static Register of instances.
BulkLoader
  
createUniqueNamedLoader(numConnections:int, logLevel:int):BulkLoader
[static] Creates a BulkLoader instance with an unique name.
BulkLoader
  
get(key:*):LoadingItem
Used to fetch an item with a given key.
BulkLoader
  
getAVM1Movie(key:String, clearMemory:Boolean = false):AVM1Movie
Returns a AVM1Movie object with the downloaded asset for the given key.
BulkLoader
  
getBitmap(key:String, clearMemory:Boolean = false):Bitmap
Returns a Bitmap object with the downloaded asset for the given key.
BulkLoader
  
getBitmapData(key:*, clearMemory:Boolean = false):BitmapData
Returns an BitmapData object with the downloaded asset for the given key.
BulkLoader
  
getContent(key:String, clearMemory:Boolean = false):*
Returns an untyped object with the downloaded asset for the given key.
BulkLoader
  
getHttpStatus(key:*):int
Gets the http status code for the loading item identified by key.
BulkLoader
  
getLoader(name:String):BulkLoader
[static] Fetched a BulkLoader object created with the name parameter.
BulkLoader
  
getMovieClip(key:String, clearMemory:Boolean = false):MovieClip
Returns a MovieClip object with the downloaded asset for the given key.
BulkLoader
  
getNetStream(key:String, clearMemory:Boolean = false):NetStream
Returns a NetStream object with the downloaded asset for the given key.
BulkLoader
  
getNetStreamMetaData(key:String, clearMemory:Boolean = false):Object
Returns a Object with meta data information for a given NetStream key.
BulkLoader
  
Returns items that haven't been fully loaded.
BulkLoader
  
Calculates the progress for a specific set of items.
BulkLoader
  
getSerializedData(key:*, clearMemory:Boolean = false, encodingFunction:Function = null):*
BulkLoader
  
getSound(key:*, clearMemory:Boolean = false):Sound
Returns a Sound object with the downloaded asset for the given key.
BulkLoader
  
getStats():String
If the logLevel if lower that LOG_ERRORS(3).
BulkLoader
  
getText(key:*, clearMemory:Boolean = false):String
Returns a String object with the downloaded asset for the given key.
BulkLoader
  
getUniqueName():String
[static]
BulkLoader
  
getXML(key:*, clearMemory:Boolean = false):XML
Returns an XML object with the downloaded asset for the given key.
BulkLoader
  
hasItem(key:*, searchAll:Boolean = true):Boolean
Checks if there is loaded item in this BulkLoader.
BulkLoader
  
loadNow(key:*):Boolean
Forces the item specified by key to be loaded right away.
BulkLoader
  
pause(key:*, loadsNext:Boolean = false):Boolean
Stop loading the item identified by key.
BulkLoader
  
pauseAll():void
Stops loading all items of this BulkLoader instance.
BulkLoader
  
[static] Stops loading all items from all BulkLoader instances.
BulkLoader
  
registerNewType(extension:String, atType:String, withClass:Class):Boolean
[static] Register a new file extension to be loaded as a given type.
BulkLoader
  
reload(key:*):Boolean
Forces the item specified by key to be reloaded right away.
BulkLoader
  
remove(key:*):Boolean
This will delete this item from memory.
BulkLoader
  
removeAll():void
Deletes all loading and loaded objects.
BulkLoader
  
[static] Deletes all content from all instances of BulkLoader class.
BulkLoader
  
Removes all items that have not succesfully loaded.
BulkLoader
  
Removes all items that have been stopped.
BulkLoader
  
resume(key:*):Boolean
Resumes loading of the item.
BulkLoader
  
resumeAll():Boolean
Resumes all loading operations that were stopped.
BulkLoader
  
Updates the priority queue
BulkLoader
  
start(withConnections:int = -1):void
Start loading all items added previously
BulkLoader
  
toString():String
Returns a string identifing this loaded instace.
BulkLoader
  
[static] Checks which BulkLoader has an item by the given key.
BulkLoader
Events
 EventSummaryDefined by
   Dispatched when all items have been downloaded and parsed.BulkLoader
   Dispatched on download progress by any of the items to download.BulkLoader
Public Constants
 ConstantDefined by
  AVAILABLE_TYPES : Array
[static]
BulkLoader
  CAN_BEGIN_PLAYING : String = "canBeginPlaying"
[static] The name of the event
BulkLoader
  CHECK_POLICY_FILE : String = "checkPolicyFile"
[static]
BulkLoader
  COMPLETE : String = "complete"
[static] The name of the event
BulkLoader
  CONTEXT : String = "context"
[static] An object definig the loading context for this load operario.
BulkLoader
  DEFAULT_LOG_LEVEL : int = 20
[static]The logging level BulkLoader will use.
BulkLoader
  DEFAULT_NUM_CONNECTIONS : int = 7
[static]
BulkLoader
  ERROR : String = "error"
[static] The name of the event
BulkLoader
  GENERAL_AVAILABLE_PROPS : Array
[static]
BulkLoader
  HEADERS : String = "headers"
[static] An array of RequestHeader objects to be used when contructing the URLRequest object.
BulkLoader
  HTTP_STATUS : String = "httpStatus"
[static] The name of the event
BulkLoader
  ID : String = "id"
[static] A String to be used to identify an item to load, can be used in any method that fetches content (as the key parameters), stops, removes and resume items.
BulkLoader
  LOG_ERRORS : int = 4
[static]Will only trace errors.
BulkLoader
  LOG_INFO : int = 2
[static]Ouputs noteworthy events such as when an item is started / finished loading.
BulkLoader
  LOG_SILENT : int = 10
[static]Nothing will be logged
BulkLoader
  LOG_VERBOSE : int = 0
[static] LogLevel: Outputs everything that is happening.
BulkLoader
  LOG_WARNINGS : int = 3
[static]Ouputs noteworthy events such as when an item is started / finished loading.
BulkLoader
  MAX_TRIES : String = "maxTries"
[static] The number, as an int, to retry downloading an item in case it fails.
BulkLoader
  OPEN : String = "open"
[static] The name of the event
BulkLoader
  PAUSED_AT_START : String = "pausedAtStart"
[static]
BulkLoader
  PREVENT_CACHING : String = "preventCache"
[static] If true a random query (or post data parameter) will be added to prevent caching.
BulkLoader
  PRIORITY : String = "priority"
[static] An int that controls which items are loaded first.
BulkLoader
  PROGRESS : String = "progress"
[static] The name of the event
BulkLoader
  TYPE_IMAGE : String = "image"
[static] Tells this class to use a Loader object to load the item.
BulkLoader
  TYPE_MOVIECLIP : String = "movieclip"
[static] Tells this class to use a Loader object to load the item.
BulkLoader
  TYPE_SOUND : String = "sound"
[static] Tells this class to use a Sound object to load the item.
BulkLoader
  TYPE_TEXT : String = "text"
[static] Tells this class to use a URLRequest object to load the item.
BulkLoader
  TYPE_VIDEO : String = "video"
[static] Tells this class to use a NetStream object to load the item.
BulkLoader
  TYPE_XML : String = "xml"
[static] Tells this class to use a XML object to load the item.
BulkLoader
  VERSION : String = "rev 196 (0.9.9.4)"
[static] Version.
BulkLoader
  WEIGHT : String = "weight"
[static]
BulkLoader
Property detail
allowsAutoIDFromFileNameproperty
allowsAutoIDFromFileName:Boolean  [read-write]

Determines if an autmatic id created from the file name. If true, when adding and item and NOT specifing an "id" props for its properties, an id with the file name will be created altomatically.

Implementation
    public function get allowsAutoIDFromFileName():Boolean
    public function set allowsAutoIDFromFileName(value:Boolean):void

Example
Automatic id:
          bulkLoader.allowsAutoIDFromFileName = false;
          var item : LoadingItem = bulkLoader.add("background.jpg")
          trace(item.id) //  outputs: null
          // now if allowsAutoIDFromFileName is set to true:
          bulkLoader.allowsAutoIDFromFileName = true;
          var item : LoadingItem = bulkLoader.add("background.jpg")
          trace(item.id) //  outputs: background
          // if you pass an id on the props, it will take precedence over auto created ids:
          bulkLoader.allowsAutoIDFromFileName = id;
          var item : LoadingItem = bulkLoader.add("background.jpg", {id:"small-bg"})
          trace(item.id) //  outputs: small-bg
          

AVAILABLE_EXTENSIONSproperty 
public static var AVAILABLE_EXTENSIONS:Array

List of all file extensions that the BulkLoader knows how to guess. Availabe types: swf, jpg, jpeg, gif, png.

avgLatencyproperty 
public var avgLatency:Number

The average latency (in miliseconds) for the entire loading.

bytesLoadedproperty 
bytesLoaded:int  [read-only]

The sum of all bytesLoaded for each item.

Implementation
    public function get bytesLoaded():int
bytesTotalproperty 
bytesTotal:int  [read-only]

The total bytes to load. If the number of items to load is larger than the number of simultaneous connections, bytesTotal will be 0 untill all connections are opened and the number of bytes for all items is known.

Implementation
    public function get bytesTotal():int

See also

bytesTotalCurrentproperty 
bytesTotalCurrent:int  [read-only]

The sum of all bytes loaded so far. If itemsTotal is less than the number of connections, this will be the same as bytesTotal. Else, bytesTotalCurrent will be available as each loading is started.

Implementation
    public function get bytesTotalCurrent():int

See also

contentsproperty 
contents:Object  [read-only]

Returns an object where the urls are the keys(as strings) and the loaded contents are the value for that key. Each value is typed as an the client must check for the right typing.

Implementation
    public function get contents():Object
highestPriorityproperty 
highestPriority:int  [read-only]

Returns the highest priority for all items in this BulkLoader instance. This will check all items, including cancelled items and already downloaded items.

Implementation
    public function get highestPriority():int
idproperty 
id:int  [read-only]

The id of this bulkLoader instance

Implementation
    public function get id():int
IMAGE_EXTENSIONSproperty 
public static var IMAGE_EXTENSIONS:Array

List of file extensions that will be automagically use a Loader object for loading. Availabe types: swf, jpg, jpeg, gif, png, image.

isFinishedproperty 
isFinished:Boolean  [read-only]Implementation
    public function get isFinished():Boolean
isRunningproperty 
isRunning:Boolean  [read-only]

A boolean indicating if the instace has started and has not finished loading all items

Implementation
    public function get isRunning():Boolean
itemsproperty 
items:Array  [read-only]

Returns a copy of all LoadingItem in this intance. This function makes a copy to avoid users messing with _items (removing items and so forth). Those can be done through functions in BulkLoader.

Implementation
    public function get items():Array
itemsLoadedproperty 
itemsLoaded:int  [read-write]

Number of items alrealdy loaded. Failed or canceled items are not taken into consideration

Implementation
    public function get itemsLoaded():int
    public function set itemsLoaded(value:int):void
itemsTotalproperty 
itemsTotal:int  [read-only]

Total number of items to load.

Implementation
    public function get itemsTotal():int
loadedRatioproperty 
loadedRatio:Number  [read-only]

The ratio (0->1) of items to load / items total. This number is always reliable.

Implementation
    public function get loadedRatio():Number
logFunctionproperty 
logFunction:Function  [read-write]

The function to be used in logging. By default it's the same as the global function trace. The log function signature is:

          public function myLogFunction(msg : String) : void{}
          

Implementation
    public function get logFunction():Function
    public function set logFunction(value:Function):void
MOVIECLIP_EXTENSIONSproperty 
public static var MOVIECLIP_EXTENSIONS:Array
nameproperty 
name:String  [read-only]

The name by which this loader instance can be identified. This property is used so you can get a reference to this instance from other classes in your code without having to save and pass it yourself, throught the static method BulkLoader.getLoader(name) .

Each name should be unique, as instantiating a BulkLoader with a name already taken will throw an error.

Implementation
    public function get name():String

See also

numConnectionsproperty 
numConnections:int  [read-only]

The number of simultaneous connections to use. This is per BulkLoader instance.

Implementation
    public function get numConnections():int

See also

percentLoadedproperty 
percentLoaded:Number  [read-only]

The percentage (0->1) of bytes loaded. Until all connections are opened this number is not reliable . If you are downloading more items than the number of simultaneous connections, use loadedRatio or weightPercent instead.

Implementation
    public function get percentLoaded():Number

See also

SOUND_EXTENSIONSproperty 
public static var SOUND_EXTENSIONS:Array

List of file extensions that will be automagically treated as sound for loading. Availabe types: mp3, f4a, f4b.

speedproperty 
speed:Number  [read-only]Implementation
    public function get speed():Number
speedAvgproperty 
public var speedAvg:Number

The average speed (in kb/s) for the entire loading.

stringSubstitutionsproperty 
stringSubstitutions:Object  [read-write]

The object, used as a hashed to substitute variables specified on the url used in add. Allows to keep common part of urls on one spot only. If later the server path changes, you can change only the stringSubstitutions object to update all items. This has to be set before the add calls are made, or else strings won't be expanded.

Implementation
    public function get stringSubstitutions():Object
    public function set stringSubstitutions(value:Object):void

See also

add

Example
Variable sustitution:
          // All webservices will be at a common path:
          bulkLoader.stringSubstitutions = {
              "web_services": "http://somesite.com/webservices"
          }
          bulkLoader.add("{web_services}/getTime");
          // this will be expanded to http://somesite.com/webservices/getTime
          
          
The format expected is {var_name} , where var_name is composed of alphanumeric characters and the underscore. Other characters (., [, ], etc) won't work, as they'll clash with the regex used in matching.

TEXT_EXTENSIONSproperty 
public static var TEXT_EXTENSIONS:Array

List of file extensions that will be automagically treated as text for loading. Availabe types: txt, js, xml, php, asp .

totalTimeproperty 
public var totalTime:Number

Time in seconds for the whole loading. Only available after everything is laoded

totalWeightproperty 
totalWeight:int  [read-only]

The sum of weights in all items to load. Each item's weight default to 1

Implementation
    public function get totalWeight():int
VIDEO_EXTENSIONSproperty 
public static var VIDEO_EXTENSIONS:Array

List of file extensions that will be automagically treated as video for loading. Availabe types: flv, f4v, f4p.

weightPercentproperty 
weightPercent:Number  [read-only]

The weighted percent of items loaded(0->1). This always returns a reliable value.

Implementation
    public function get weightPercent():Number
XML_EXTENSIONSproperty 
public static var XML_EXTENSIONS:Array
Constructor detail
BulkLoader()constructor
public function BulkLoader(name:String, numConnections:int, logLevel:int)

Creates a new BulkLoader object identifiable by the name parameter. The name parameter must be unique, else an Error will be thrown.

Parameters
name:String — A name that can be used later to reference this loader in a static context,
 
numConnections:int — numConnections The number of maximum simultaneous connections to be open.
 
logLevel:int — logLevel At which level should traces be outputed. By default only errors will be traced.

See also

Method detail
add()method
public function add(url:*, props:Object = null):LoadingItem

Adds a new assets to be loaded. The BulkLoader object will manage diferent assets type. If the right type cannot be infered from the url termination (e.g. the url ends with ".swf") the BulkLoader will relly on the type property of the props parameter. If both are set, the type property of the props object will overrite the one defined in the url. In case none is specified and the url won't hint at it, the type TYPE_TEXT will be used.

Parameters
url:* — String OR URLRequest A String or a URLRequest instance.
 
props:Object (default = null) — An object specifing extra data for this loader. The following properties are supported:

Property name Class constant Data type Description
preventCache PREVENT_CACHING Boolean If true a random query string will be added to the url (or a post param in case of post reuquest).
id ID String A string to identify this item. This id can be used in any method that uses the key parameter, such as pause, removeItem, resume, getContent, getBitmap, getBitmapData, getXML, getMovieClip and getText.
priorityPRIORITY int An int used to order which items till be downloaded first. Items with a higher priority will download first. For items with the same priority they will be loaded in the same order they've been added.
maxTriesMAX_TRIES int The number of retries in case the lading fails, defaults to 3.
weightWEIGHT int A number that sets an arbitrary relative size for this item. See #weightPercent.
headersHEADERS Array An array of RequestHeader objects to be used when constructing the URL. If the url parameter is passed as a string, BulkLoader will use these request headers to construct the url.
contextCONTEXT LoaderContext or SoundLoaderContext An object definig the loading context for this load operario. If this item is of TYPE_SOUND, a SoundLoaderContext is expected. If it's a TYPE_IMAGE a LoaderContext should be passed.
pausedAtStartPAUSED_AT_START Boolean If true, the nestream will be paused when loading has begun.
You can use string substitutions (variable expandsion).

Returns
LoadingItem

See also


Example
Retriving contents:
import br.stimuli.loaded.BulkLoader;
var bulkLoader : BulkLoader = new BulkLoader("main");
// simple item:
bulkLoader.add("config.xml");
// use an id that can be retirved latterL
bulkLoader.add("background.jpg", {id:"bg"});
// or use a static var to have auto-complete and static checks on your ide:
bulkLoader.add("background.jpg", {BulkLoader.ID:"bg"});
// loads the languages.xml file first and parses before all items are done:
public function parseLanguages() : void{
   var theLangXML : XML = bulkLoader.getXML("langs");
   // do something wih the xml:
   doSomething(theLangXML);
}
bulkLoader.add("languages.xml", {priority:10, onComplete:parseLanguages, id:"langs"});
// Start the loading operation with only 3 simultaneous connections:
bulkLoader.start(3)
   

changeItemPriority()method 
public function changeItemPriority(key:String, newPriority:int):Boolean

Updates the priority of item identified by key with a new value, the queue will be re resorted right away. Changing priorities will not stop currently opened connections.

Parameters
key:String — The url request, url as a string or a id from which the asset was loaded.
 
newPriority:int — The priority to assign to the item.

Returns
Boolean — The true if an item with that key was found, false othersiwe.
clear()method 
public function clear():void

Removes this instance from the static Register of instances. After a clear method has been called for a given instance, nothing else should work

createUniqueNamedLoader()method 
public static function createUniqueNamedLoader(numConnections:int, logLevel:int):BulkLoader

Creates a BulkLoader instance with an unique name. This is useful for situations where you might be creating many BulkLoader instances and it gets tricky to garantee that no other instance is using that name.

Parameters
numConnections:int — numConnections The number of maximum simultaneous connections to be open.
 
logLevel:int — logLevel At which level should traces be outputed. By default only errors will be traced.

Returns
BulkLoader — A BulkLoader intance, with an unique name.
get()method 
public function get(key:*):LoadingItem

Used to fetch an item with a given key. The returned LoadingItem can be used to attach event listeners for the individual items (Event.COMPLETE, ProgressEvent.PROGRESS, Event.START).

Parameters
key:* — A url (as a string or urlrequest) or an id to fetch

Returns
LoadingItem — The corresponding LoadingItem or null if one isn't found.
getAVM1Movie()method 
public function getAVM1Movie(key:String, clearMemory:Boolean = false):AVM1Movie

Returns a AVM1Movie object with the downloaded asset for the given key.

Parameters
key:String — The url request, url as a string or a id from which the asset was loaded. Returns null if the cast fails
 
clearMemory:Boolean (default = false) — If this BulkProgressEvent instance should clear all references to the content of this asset.

Returns
AVM1Movie — The content retrived from that url casted to a AVM1Movie object. Returns null if the cast fails.
getBitmap()method 
public function getBitmap(key:String, clearMemory:Boolean = false):Bitmap

Returns a Bitmap object with the downloaded asset for the given key.

Parameters
key:String — The url request, url as a string or a id from which the asset was loaded. Returns null if the cast fails
 
clearMemory:Boolean (default = false) — If this BulkProgressEvent instance should clear all references to the content of this asset.

Returns
Bitmap — The content retrived from that url casted to a Bitmap object. Returns null if the cast fails.
getBitmapData()method 
public function getBitmapData(key:*, clearMemory:Boolean = false):BitmapData

Returns an BitmapData object with the downloaded asset for the given key.

Parameters
key:* — The url request, url as a string or a id from which the asset was loaded. Returns null if the cast fails. Does not clone the original bitmap data from the bitmap asset.
 
clearMemory:Boolean (default = false) — If this BulkProgressEvent instance should clear all references to the content of this asset.

Returns
BitmapData — The content retrived from that url casted to a BitmapData object. Returns null if the cast fails.
getContent()method 
public function getContent(key:String, clearMemory:Boolean = false):*

Returns an untyped object with the downloaded asset for the given key.

Parameters
key:String — The url request, url as a string or a id from which the asset was loaded.
 
clearMemory:Boolean (default = false) — If this BulkProgressEvent instance should clear all references to the content of this asset.

Returns
* — The content retrived from that url
getHttpStatus()method 
public function getHttpStatus(key:*):int

Gets the http status code for the loading item identified by key.

Parameters
key:* — The url request, url as a string or a id from which the asset was loaded.

Returns
int — The Http status as an integer. If no item is found returns -1. If the http status cannot be determined but the item was found, returns 0.
getLoader()method 
public static function getLoader(name:String):BulkLoader

Fetched a BulkLoader object created with the name parameter. This is usefull if you must access loades assets from another scope, without having to pass direct references to this loader.

Parameters
name:String — name The name of the loader to be fetched.

Returns
BulkLoader — The BulkLoader instance that was registred with that name. Returns null if none is found.
getMovieClip()method 
public function getMovieClip(key:String, clearMemory:Boolean = false):MovieClip

Returns a MovieClip object with the downloaded asset for the given key.

Parameters
key:String — The url request, url as a string or a id from which the asset was loaded. Returns null if the cast fails
 
clearMemory:Boolean (default = false) — If this BulkProgressEvent instance should clear all references to the content of this asset.

Returns
MovieClip — The content retrived from that url casted to a MovieClip object. Returns null if the cast fails.
getNetStream()method 
public function getNetStream(key:String, clearMemory:Boolean = false):NetStream

Returns a NetStream object with the downloaded asset for the given key.

Parameters
key:String — The url request, url as a string or a id from which the asset was loaded. Returns null if the cast fails
 
clearMemory:Boolean (default = false) — If this BulkProgressEvent instance should clear all references to the content of this asset.

Returns
NetStream — The content retrived from that url casted to a NetStream object. Returns null if the cast fails.
getNetStreamMetaData()method 
public function getNetStreamMetaData(key:String, clearMemory:Boolean = false):Object

Returns a Object with meta data information for a given NetStream key.

Parameters
key:String — The url request, url as a string or a id from which the asset was loaded. Returns null if the cast fails
 
clearMemory:Boolean (default = false) — If this BulkProgressEvent instance should clear all references to the content of this asset.

Returns
Object — The meta data object downloaded with this NetStream. Returns null if the given key does not resolve to a NetStream.
getNotLoadedItems()method 
public function getNotLoadedItems():Array

Returns items that haven't been fully loaded.

Returns
Array — An array with all LoadingItems not fully loaded.
getProgressForItems()method 
public function getProgressForItems(keys:Array):BulkProgressEvent

Calculates the progress for a specific set of items.

Parameters
keys:Array — An Array containing keys (ids or urls) or LoadingItem objects to measure progress of.

Returns
BulkProgressEvent — A BulkProgressEvent object with the current progress status.

See also

getSerializedData()method 
public function getSerializedData(key:*, clearMemory:Boolean = false, encodingFunction:Function = null):*Parameters
key:*
 
clearMemory:Boolean (default = false)
 
encodingFunction:Function (default = null)

Returns
*
getSound()method 
public function getSound(key:*, clearMemory:Boolean = false):Sound

Returns a Sound object with the downloaded asset for the given key.

Parameters
key:* — key The url request, url as a string or a id from which the asset was loaded. Returns null if the cast fails
 
clearMemory:Boolean (default = false) — clearMemory Boolean If this BulkProgressEvent instance should clear all references to the content of this asset.

Returns
Sound — The content retrived from that url casted to a Sound object. Returns null if the cast fails.
getStats()method 
public function getStats():String

If the logLevel if lower that LOG_ERRORS(3). Outputs a host of statistics about the loading operation

Returns
String — A formated string with loading statistics.

See also

getText()method 
public function getText(key:*, clearMemory:Boolean = false):String

Returns a String object with the downloaded asset for the given key.

Parameters
key:* — The url request, url as a string or a id from which the asset was loaded. Returns null if the cast fails
 
clearMemory:Boolean (default = false) — If this BulkProgressEvent instance should clear all references to the content of this asset.

Returns
String — The content retrived from that url casted to a String object. Returns null if the cast fails.
getUniqueName()method 
public static function getUniqueName():String

Returns
String
getXML()method 
public function getXML(key:*, clearMemory:Boolean = false):XML

Returns an XML object with the downloaded asset for the given key.

Parameters
key:* — key String OR URLRequest The url request, url as a string or a id from which the asset was loaded. Returns null if the cast fails
 
clearMemory:Boolean (default = false) — If this BulkProgressEvent instance should clear all references to the content of this asset.

Returns
XML — The content retrived from that url casted to a XML object. Returns null if the cast fails.
hasItem()method 
public function hasItem(key:*, searchAll:Boolean = true):Boolean

Checks if there is loaded item in this BulkLoader.

Parameters
key:* — The url (as a String or a URLRequest object)or an id (as a String) by which the item is identifiable.
 
searchAll:Boolean (default = true) — searchAll If true will search through all BulkLoader instances. Else will only search this one.

Returns
Boolean — True if a loader has a loaded item stored.
loadNow()method 
public function loadNow(key:*):Boolean

Forces the item specified by key to be loaded right away. This will stop any open connection as needed. If needed, the connection to be closed will be the one with the lower priority. In case of a tie, the one that has more bytes to complete will be removed. The item to load now will be automatically be set the highest priority value in this BulkLoader instance.

Parameters
key:* — The url request, url as a string or a id from which the asset was created.

Returns
BooleanTrue if an item with that key is found, false otherwise.
pause()method 
public function pause(key:*, loadsNext:Boolean = false):Boolean

Stop loading the item identified by key. This will not remove the item from the BulkLoader. Note that progress notification will jump around, as the stopped item will still count as something to load, but it's byte count will be 0.

Parameters
key:* — The key (url as a string, url as a URLRequest or an id as a String).
 
loadsNext:Boolean (default = false) — If it should start loading the next item.

Returns
Boolean — A Boolean indicating if the object has been stopped.
pauseAll()method 
public function pauseAll():void

Stops loading all items of this BulkLoader instance. This does not clear or remove items from the qeue.

pauseAllLoaders()method 
public static function pauseAllLoaders():void

Stops loading all items from all BulkLoader instances.

See also

registerNewType()method 
public static function registerNewType(extension:String, atType:String, withClass:Class):Boolean

Register a new file extension to be loaded as a given type. This is used both in the guessing of types from the url and affects how loading is done for each type. If you are adding an extension to be of a type you are creating, you must pass the withClass parameter, which should be a class that extends LoadingItem.

Parameters
extension:String — extension The file extension to be used (can include the dot or not)
 
atType:String — atType Which type this extension will be associated with.
 
withClass:Class — withClass For new types (not new extensions) wich class that extends LoadingItem should be used to mange this item.

Returns
Boolean — A Boolean indicating if the new extension was registered.

See also

reload()method 
public function reload(key:*):Boolean

Forces the item specified by key to be reloaded right away. This will stop any open connection as needed.

Parameters
key:* — The url request, url as a string or a id from which the asset was created.

Returns
BooleanTrue if an item with that key is found, false otherwise.
remove()method 
public function remove(key:*):Boolean

This will delete this item from memory. It's content will be inaccessible after that.

Parameters
key:* — A url (as a string or urlrequest) or an id to fetch

Returns
BooleanTrue if an item with that key has been removed, and false othersiwe.
removeAll()method 
public function removeAll():void

Deletes all loading and loaded objects. This will stop all connections and delete from the cache all of it's items (no content will be accessible if removeAll is executed).

removeAllLoaders()method 
public static function removeAllLoaders():void

Deletes all content from all instances of BulkLoader class. This will stop any pending loading operations as well as free memory.

See also

removeFailedItems()method 
public function removeFailedItems():int

Removes all items that have not succesfully loaded. After removing, it will try to restart loading if there are still items to load.

Returns
int
removePausedItems()method 
public function removePausedItems():Boolean

Removes all items that have been stopped. After removing, it will try to restart loading if there are still items to load.

Returns
Boolean
resume()method 
public function resume(key:*):Boolean

Resumes loading of the item. Depending on the environment the player is running, resumed items will be able to use partialy downloaded content.

Parameters
key:* — key The url request, url as a string or a id from which the asset was loaded.

Returns
Boolean — If a item with that key has resumed loading.
resumeAll()method 
public function resumeAll():Boolean

Resumes all loading operations that were stopped.

Returns
BooleanTrue if any item was stopped and resumed, false otherwise
sortItemsByPriority()method 
public function sortItemsByPriority():void

Updates the priority queue

start()method 
public function start(withConnections:int = -1):void

Start loading all items added previously

Parameters
withConnections:int (default = -1) — withConnections [optional]The maximum number of connections to make at the same time. If specified, will override the parameter passed (if any) to the constructor.

See also

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

Returns a string identifing this loaded instace.

Returns
String
whichLoaderHasItem()method 
public static function whichLoaderHasItem(key:*):BulkLoader

Checks which BulkLoader has an item by the given key.

Parameters
key:* — The url (as a String or a URLRequest object)or an id (as a String) by which the item is identifiable.

Returns
BulkLoader — The BulkLoader instance that has the given key or null if no key if found in any loader.
Event detail
completeevent 
Event object type: br.com.stimuli.loading.BulkProgressEvent

Dispatched when all items have been downloaded and parsed.

progressevent  
Event object type: br.com.stimuli.loading.BulkProgressEvent

Dispatched on download progress by any of the items to download.

Constant detail
AVAILABLE_TYPESconstant
public static const AVAILABLE_TYPES:Array
CAN_BEGIN_PLAYINGconstant 
public static const CAN_BEGIN_PLAYING:String = "canBeginPlaying"

The name of the event

CHECK_POLICY_FILEconstant 
public static const CHECK_POLICY_FILE:String = "checkPolicyFile"
COMPLETEconstant 
public static const COMPLETE:String = "complete"

The name of the event

CONTEXTconstant 
public static const CONTEXT:String = "context"

An object definig the loading context for this load operario. If this item is of TYPE_SOUND, a SoundLoaderContext is expected. If it's a TYPE_IMAGE a LoaderContext should be passed. Checked when adding a new item to load.

See also

DEFAULT_LOG_LEVELconstant 
public static const DEFAULT_LOG_LEVEL:int = 20

The logging level BulkLoader will use.

See also

DEFAULT_NUM_CONNECTIONSconstant 
public static const DEFAULT_NUM_CONNECTIONS:int = 7
ERRORconstant 
public static const ERROR:String = "error"

The name of the event

GENERAL_AVAILABLE_PROPSconstant 
public static const GENERAL_AVAILABLE_PROPS:Array
HEADERSconstant 
public static const HEADERS:String = "headers"

An array of RequestHeader objects to be used when contructing the URLRequest object. If the url parameter is passed as a URLRequest object it will be ignored. Checked when adding a new item to load.

See also

HTTP_STATUSconstant 
public static const HTTP_STATUS:String = "httpStatus"

The name of the event

IDconstant 
public static const ID:String = "id"

A String to be used to identify an item to load, can be used in any method that fetches content (as the key parameters), stops, removes and resume items. Checked when adding a new item to load.

See also

LOG_ERRORSconstant 
public static const LOG_ERRORS:int = 4

Will only trace errors. Defaut level

LOG_INFOconstant 
public static const LOG_INFO:int = 2

Ouputs noteworthy events such as when an item is started / finished loading.

LOG_SILENTconstant 
public static const LOG_SILENT:int = 10

Nothing will be logged

LOG_VERBOSEconstant 
public static const LOG_VERBOSE:int = 0

LogLevel: Outputs everything that is happening. Usefull for debugging.

LOG_WARNINGSconstant 
public static const LOG_WARNINGS:int = 3

Ouputs noteworthy events such as when an item is started / finished loading.

MAX_TRIESconstant 
public static const MAX_TRIES:String = "maxTries"

The number, as an int, to retry downloading an item in case it fails. Checked when adding a new item to load.

The default value is 3.

See also

OPENconstant 
public static const OPEN:String = "open"

The name of the event

PAUSED_AT_STARTconstant 
public static const PAUSED_AT_START:String = "pausedAtStart"
PREVENT_CACHINGconstant 
public static const PREVENT_CACHING:String = "preventCache"

If true a random query (or post data parameter) will be added to prevent caching. Checked when adding a new item to load.

See also

PRIORITYconstant 
public static const PRIORITY:String = "priority"

An int that controls which items are loaded first. Items with a higher PRIORITY will load first. If more than one item has the same PRIORITY number, the order in which they are added will be taken into consideration. Checked when adding a new item to load.

See also

PROGRESSconstant 
public static const PROGRESS:String = "progress"

The name of the event

TYPE_IMAGEconstant 
public static const TYPE_IMAGE:String = "image"

Tells this class to use a Loader object to load the item.

TYPE_MOVIECLIPconstant 
public static const TYPE_MOVIECLIP:String = "movieclip"

Tells this class to use a Loader object to load the item.

TYPE_SOUNDconstant 
public static const TYPE_SOUND:String = "sound"

Tells this class to use a Sound object to load the item.

TYPE_TEXTconstant 
public static const TYPE_TEXT:String = "text"

Tells this class to use a URLRequest object to load the item.

TYPE_VIDEOconstant 
public static const TYPE_VIDEO:String = "video"

Tells this class to use a NetStream object to load the item.

TYPE_XMLconstant 
public static const TYPE_XML:String = "xml"

Tells this class to use a XML object to load the item.

VERSIONconstant 
public static const VERSION:String = "rev 196 (0.9.9.4)"

Version. Useful for debugging.

WEIGHTconstant 
public static const WEIGHT:String = "weight"