XMLLoader

Kind of class:class
Inherits from:Dispatcher
Author:Martijn de Visser
Classpath:org.asapframework.util.xml.XMLLoader
File last modified:Sunday, 05 November 2006, 11:27:56
Loads XML files. For your convenience, this class won't allow more than 3 simultaneous XML.load calls, to prevent this Flash Player bug: http://www.macromedia.com/go/c0da292b from occuring.

More than three simulaneous calls are placed in a queue and loaded sequentially.
Usage:
  • var myXMLLoader:XMLLoader = XMLLoader.getInstance();
    myXMLLoader.addEventListener( XMLEvent.ON_LOADED, this );
    myXMLLoader.load("../xml/myfile.xml", "myFile");
    In your listening class ('this' in example):
    public function onXMLLoaded (e:XMLEvent) : Void {
        // handle result
    }
Events broadcasted to listeners:
  • XMLEvent with type: ON_ERROR
    • (null)
  • XMLEvent with type: ON_LOADED
    • for 'onXMLLoadError' event
  • XMLEvent with type: ON_ALL_LOADED
    • for 'onXMLTimeout' event

Summary


Constructor
Instance properties
Class methods
  • XMLError (inError:Number) : String
    • Converts an XML error to a string.
  • getInstance : XMLLoader
    • Returns reference to singleton instance of XMLLoader.
Instance methods
  • load (inURL:String, inName:String, inNoCache:Boolean, inTimeOut:Number) : Boolean
    • Loads an XML file.
  • startLoading (inWorker:XMLWorker) : Boolean
    • Tries to start loading the file.
  • loadNext : Void
    • Loads the next file in the queue that's not being loaded yet.
  • removeWorker (inWorker:XMLWorker) : Void
    • Removes a wrapper from the queue and breaks listener relation.
  • toString : String
Event handlers

Constructor

XMLLoader

function XMLLoader (
)

Private constructor, use getInstance to refer to the singleton instance.

Class properties

ERROR_ATTRIBUTE_TERMINATION

static ERROR_ATTRIBUTE_TERMINATION:Number = -8
(read)

ERROR_CDATA_TERMINATION

static ERROR_CDATA_TERMINATION:Number = -2
(read)

ERROR_COMMENT_TERMINATION

static ERROR_COMMENT_TERMINATION:Number = -5
(read)

ERROR_DOCTYPE_TERMINATION

static ERROR_DOCTYPE_TERMINATION:Number = -4
(read)

ERROR_ELEMENT_MALFORMED

static ERROR_ELEMENT_MALFORMED:Number = -6
(read)

ERROR_ENDTAG_WITHOUT_STARTTAG

static ERROR_ENDTAG_WITHOUT_STARTTAG:Number = -10
(read)

ERROR_OUT_OF_MEMORY

static ERROR_OUT_OF_MEMORY:Number = -7
(read)

ERROR_STARTTAG_WITHOUT_ENDTAG

static ERROR_STARTTAG_WITHOUT_ENDTAG:Number = -9
(read)

ERROR_TIMEOUT

static ERROR_TIMEOUT:Number = -100
(read)

ERROR_XML_TERMINATION

static ERROR_XML_TERMINATION:Number = -3
(read)

instance

static private instance:XMLLoader = null
(read)

MAX_CALLS

static private MAX_CALLS:Number = 3
(read)

mCurrentCalls

static private mCurrentCalls:Number = 0
(read)

of XMLWorker objects

Instance properties

mWorkerQueue

private mWorkerQueue:Array
(read)

Class methods

getInstance

static function getInstance (

Returns reference to singleton instance of XMLLoader.

XMLError

static private function XMLError (
inError:Number) : String

Converts an XML error to a string.

Instance methods

load

function load (
inURL:String, inName:String, inNoCache:Boolean, inTimeOut:Number) : Boolean

Loads an XML file.
Parameters:
inURL :
The URL of the xml file
inName :
Unique identifier; this name will also be used in callback events when file was loaded or when an error was encountered.
inNoCache:
If set to true, the xml file will always be fetched from the server by appending a timestamp to the call, thus circumventing the local browser cache.
inTimeOut:
Set value to specify time to wait (in milliseconds) for a server response (excluding the download time of the actual XML data itself). Defaults to 10 seconds if no value is specified. Set to '0' to disable timeout.
Returns:
  • Boolean, false if XML document couldn't be added (because name already exists is list).

loadNext

private function loadNext (
) : Void

Loads the next file in the queue that's not being loaded yet.
Events broadcasted to listeners:
  • XMLEvent with type: ON_ALL_LOADED
    • for 'onXMLTimeout' event

removeWorker

private function removeWorker (
inWorker:XMLWorker) : Void

Removes a wrapper from the queue and breaks listener relation.

startLoading

private function startLoading (
inWorker:XMLWorker) : Boolean

Tries to start loading the file.
Parameters:
inWorker:
XMLWorker
Returns:
  • Boolean indicating if we could start or not.

toString

function toString (
) : String

Event handlers

onXMLLoaded

private function onXMLLoaded (
e:XMLWorkerEvent) : Void

Callback from XMLWorker
Events broadcasted to listeners:
  • XMLEvent with type: ON_ERROR
    • (null)
  • XMLEvent with type: ON_LOADED
    • for 'onXMLLoadError' event

onXMLTimeout

function onXMLTimeout (
e:XMLWorkerEvent) : Void

Triggered if no response from server was received within timeout interval.