BiResourceLoader

This class is used to load different kinds of resources. There are basically 3 types of resources that this class can handle. The first 2 are script files and a code string. The third one is a genereal object described by an XML element and in this case an object is created using a BiXmlResourceParser.

When creating general objects a few special rules apply. If the created object is an event target the resource loader will listen to load and error events so that it can be notified by the object that it is loaded. If the object has a load() method that will be called if the object is not already loaded. To decide if the object is loaded the resource loader will use getLoaded() if available and if that isn't available it is assumed that the object is loaded (or does not require loading).

This class extends BiEventTarget and therefore all methods and fields available for BiEventTarget are also available for BiResourceLoader .

Constructor

new BiResourceLoader ( oScriptLoaderQueueConstructor )

Parameters

NameTypeOptionalDefaultDescripton
oScriptLoaderQueueConstructorObjectThis is the constructor if the script loader queue to use, default is BiScriptLoaderQueue

Properties

NameTypegetsetDescripton
autoNameMappingBooleancheckedcheckedWhen this is true any XML object that has an id attribute will create a global reference to the object created from this XML element.
countNumbercheckedThe number of added resources
loadedBooleancheckedWhether all resources have been loaded.
loadedCountNumbercheckedThe number of finished loading resources. This includes inline scripts and general objects as well.
scriptLoaderQueueConstructorObjectcheckedThe constructor of the script loaded queue, default is BiScriptLoaderQueue.

Methods

NameDescription
abortStops the current loading
addResourceAdds a resource that the resource loader will instantiate and load.
addResourcesFromNodeThis method is used to load resources by BiAdf and BiCustomClass. It loads resources defined as child nodes on a node.
getResourceByIdReturns the resource with the given id
loadStarts the loading of the resource. The loading is done asynchronously so this will return immediately. When all resources are loaded the load event will fire.

Events

NameTypeBubblesDescripton
loadBiEventFires when all the resources have been loaded and executed
progressBiEventFires every time one of the external resources have been loaded. This is useful for providing visual feedback.

Static Methods

None.

Static Fields

None.

Remarks

None.

Method Details

abort

Stops the current loading

Syntax

object.abort ( )

Parameters

No arguments.

Return Type

void

addResource

Adds a resource that the resource loader will instantiate and load.

Syntax

object.addResource ( sType,oData,sId )

Parameters

NameTypeOptionalDefaultDescripton
sTypeStringThis is either one of the following 2 types or the name of the class to use to instantiate the object. If a class name is passed then the oData argument should be an XML element that is then used to describe the object.

script - the oData is treated as URI of the script file
inlinescript - the oDate string is treated as the script code
oDataObjectFor script this should be the URI of the script file. This is URI is relative to the ADF file. For inlinescript this is the script code as a string. For a general object this should be an XML element that is then passed to a BiXmlResourceLoader which will instantiate the object.
sIdStringOptional id to use to find the source using getResourceById. If a general object is used the id attribute in the XML element is used instead.

Return Type

void

addResourcesFromNode

This method is used to load resources by BiAdf and BiCustomClass. It loads resources defined as child nodes on a node.

Syntax

object.addResourcesFromNode ( oNode )

Parameters

NameTypeOptionalDefaultDescripton
oNodeNodeDOM node to load children of.

Return Type

void

getResourceById

Returns the resource with the given id

Syntax

object.getResourceById ( sId )

Parameters

NameTypeOptionalDefaultDescripton
sIdStringThe id of the resource to lookup

Return Type

Object

load

Starts the loading of the resource. The loading is done asynchronously so this will return immediately. When all resources are loaded the load event will fire.

Syntax

object.load ( )

Parameters

No arguments.

Return Type

void