} else {
trace("Unable to load XML");
}
};
my_xml.load("http://www.helpexamples.com/flash/xml/ds.xml");
pBar_mc.onEnterFrame = function() {
var pctLoaded:Number = Math.floor(my_xml.getBytesLoaded() /
my_xml.getBytesTotal() * 100);
if (!isNaN(pctLoaded)) {
pBar_mc.bar_mc._xscale = pctLoaded;
pBar_mc.label_txt.text = pctLoaded + "% loaded";
if (pctLoaded >= 100) {
pBar_mc.onEnterFrame = undefined;
}
}
};
The previous code is broken down into seven sections. The first section defines the width
and height of the progress bar when it is drawn on the Stage. The progress bar will be
centered on the Stage in an upcoming section. The next section of code creates two movie
clips,
and
pBar_mc
bar_mc
red rectangle on the Stage. The
external XML file loads from the remote website.
Next, a second movie clip is nested inside of the
movie clip draws an outline on the Stage that matches the dimensions
stroke_mc
specified by the
barHeight
fourth section of code creates within the
display what percentage of the XML file has already loaded, similar to the label on the
ProgressBar component. Next, the
,
, and
bar_mc
stroke_mc
The sixth section of code defines a new XML object instance, which is used to load an
external XML file. An onLoad event handler is defined and traces a message to the Output
panel. The onLoad event handler also deletes the
defined in the next section) for the
an
event handler for the
onEnterFrame
how much of the external XML file has loaded and modifies the
movie clip. First the
bar_mc
the file has finished downloading. As long as the percentage of the file loaded is a valid
number, the
_xscale
displays what percentage of the file has loaded. If the file has completed loading (percent
loaded reaches 100%) the
no longer monitored.
. The
movie clip is nested inside
bar_mc
instance modifies its
bar_mc
and
variables defined in the first section. The
barWidth
pBar_mc
pBar_mc
instances) is centered on the Stage.
label_txt
pBar_mc
pBar_mc
onEnterFrame
property for
bar_mc
event handler is deleted so download progress is
onEnterFrame
_xscale
movie clip,
pBar_mc
movie clip a text field that is used to
movie clip (which includes the nested
onEnterFrame
movie clip. The final section of code defines
movie clip. This event handler monitors
event handler calculates what percentage of
is set, and the text field within
Sending and loading variables
, and draws a
pBar_mc
property as the
. The
stroke_mc
event handler (which is
property for the
_xscale
pBar_mc
637
Need help?
Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?