03.05.2013 Views

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - 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.

onLoad (LoadVars.onLoad h<strong>and</strong>ler)<br />

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

Invoked when a LoadVars.load() or LoadVars.sendAndLoad() operation has ended. If the<br />

operation was successful, my_lv is populated with variables downloaded by the operation, <strong>and</strong><br />

these variables are available when this h<strong>and</strong>ler is invoked.<br />

This h<strong>and</strong>ler is undefined by default.<br />

This event h<strong>and</strong>ler is similar to XML.onLoad.<br />

Parameters<br />

success:Boolean - A Boolean value that indicates whether the load operation ended in<br />

success (true) or failure (false).<br />

Example<br />

For the following example, add a TextInput instance called name_ti, a TextArea instance<br />

called result_ta, <strong>and</strong> a Button instance called submit_button to the Stage. When the user<br />

clicks the Login button instance in the following example, two LoadVars objects are created:<br />

send_lv <strong>and</strong> result_lv. The send_lv object copies the name from the name_ti instance<br />

<strong>and</strong> sends the data to greeting.cfm. The result from this script loads into the result_lv<br />

object, <strong>and</strong> the server response displays in the TextArea instance (result_ta). Add the<br />

following ActionScript on Frame 1 of the Timeline:<br />

var submitListener:Object = new Object();<br />

submitListener.click = function(evt:Object) {<br />

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

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

if (success) {<br />

result_ta.text = result_lv.welcomeMessage;<br />

} else {<br />

result_ta.text = "Error connecting to server.";<br />

}<br />

};<br />

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

send_lv.name = name_ti.text;<br />

send_lv.sendAndLoad("http://www.flash-mx.com/mm/greeting.cfm",<br />

result_lv, "POST");<br />

};<br />

submit_button.addEventListener("click", submitListener);<br />

To view a more robust example, see the login.fla file at www.adobe.com/go/learn_fl_samples.<br />

Download <strong>and</strong> decompress the .zip file <strong>and</strong> navigate to the folder for your version of<br />

ActionScript to access the sample.<br />

372 ActionScript classes

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

Saved successfully!

Ooh no, something went wrong!