User Guide

1026 Chapter 2: ActionScript Language Reference
XML.getBytesLoaded()
Availability
Flash Player 6.
Usage
my_xml.getBytesLoaded() : Number
Parameters
None.
Returns
An integer that indicates the number of bytes loaded.
Description
Method; returns the number of bytes loaded (streamed) for the XML document. You can
compare the value of
getBytesLoaded() with the value of getBytesTotal() to determine what
percentage of an XML document has loaded.
Example
The following example shows how to use the XML.getBytesLoaded() method with the
XML.getBytesTotal() method to trace the progress of an XML.load() command. You must replace
the URL parameter of the
XML.load() command so that the parameter refers to a valid XML file
using HTTP. If you attempt to use this example to load a local file that resides on your hard disk,
this example will not work properly because in test movie mode Flash Player loads local files in
their entirety.
// create a new XML document
var doc:XML = new XML();
var checkProgress = function(xmlObj:XML) {
var bytesLoaded:Number = xmlObj.getBytesLoaded();
var bytesTotal:Number = xmlObj.getBytesTotal();
var percentLoaded:Number = Math.floor((bytesLoaded / bytesTotal ) * 100);
trace ("milliseconds elapsed: " + getTimer());
trace ("bytesLoaded: " + bytesLoaded);
trace ("bytesTotal: " + bytesTotal);
trace ("percent loaded: " + percentLoaded);
trace ("---------------------------------");
}
doc.onLoad = function(success:Boolean) {
clearInterval(intervalID);
trace("intervalID: " + intervalID);
}
doc.load("[place a valid URL pointing to an XML file here]");
var intervalID:Number = setInterval(checkProgress, 100, doc);
See also
XML.getBytesTotal()