03.05.2013 Views

ActionScript 2.0 Language Reference - Adobe Help and Support

ActionScript 2.0 Language Reference - Adobe Help and Support

ActionScript 2.0 Language Reference - Adobe Help and Support

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Example<br />

The following example uses a ProgressBar instance <strong>and</strong> a LoadVars object to download a text<br />

file. When you test the file, two things are displayed in the Output panel: whether the file<br />

loads successfully <strong>and</strong> how much data loads into the SWF file. You must replace the URL<br />

parameter of the LoadVars.load() comm<strong>and</strong> so that the parameter refers to a valid text file<br />

using HTTP. If you attempt to use this example to load a local file that resides on your hard<br />

disk, this example will not work properly because in test movie mode Flash Player loads local<br />

files in their entirety. To see this code work, add a ProgressBar instance called loadvars_pb to<br />

the Stage. Then add the following <strong>ActionScript</strong> to Frame 1 of the Timeline:<br />

var loadvars_pb:mx.controls.ProgressBar;<br />

var my_lv:LoadVars = new LoadVars();<br />

loadvars_pb.mode = "manual";<br />

this.createEmptyMovieClip("timer_mc", 999);<br />

timer_mc.onEnterFrame = function() {<br />

var lvBytesLoaded:Number = my_lv.getBytesLoaded();<br />

var lvBytesTotal:Number = my_lv.getBytesTotal();<br />

if (lvBytesTotal != undefined) {<br />

trace("Loaded "+lvBytesLoaded+" of "+lvBytesTotal+" bytes.");<br />

loadvars_pb.setProgress(lvBytesLoaded, lvBytesTotal);<br />

}<br />

};<br />

my_lv.onLoad = function(success:Boolean) {<br />

loadvars_pb.setProgress(my_lv.getBytesLoaded(), my_lv.getBytesTotal());<br />

delete timer_mc.onEnterFrame;<br />

if (success) {<br />

trace("LoadVars loaded successfully.");<br />

} else {<br />

trace("An error occurred while loading variables.");<br />

}<br />

};<br />

my_lv.load("[place a valid URL pointing to a text file here]");<br />

See also<br />

load (LoadVars.load method), sendAndLoad (LoadVars.sendAndLoad method)<br />

load (LoadVars.load method)<br />

public load(url:String) : Boolean<br />

Downloads variables from the specified URL, parses the variable data, <strong>and</strong> places the resulting<br />

variables in my_lv. Any properties in my_lv with the same names as downloaded variables are<br />

overwritten. Any properties in my_lv with different names than downloaded variables are not<br />

deleted. This is an asynchronous action.<br />

LoadVars 709

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!