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.

Parameters<br />

url:String - A string; the URL to which to upload variables. If the SWF file issuing this call<br />

is running in a web browser, url must be in the same domain as the SWF file.<br />

target:Object - The LoadVars or XML object that receives the downloaded variables.<br />

method:String [optional] - A string; the GET or POST method of the HTTP protocol. The<br />

default value is POST.<br />

Returns<br />

Boolean - A Boolean value.<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 to 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 in the ActionScript samples folder at<br />

www.adobe.com/go/learn_fl_samples. Download <strong>and</strong> decompress the .zip file <strong>and</strong> navigate to<br />

the folder for your version of ActionScript to access the sample.<br />

See also<br />

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

(XML.sendAndLoad method)<br />

LoadVars 375

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

Saved successfully!

Ooh no, something went wrong!