Recipe 13.11. Retrieving Text Field, Text Input, and Text Area Values


Problem

You want to retrieve the value from a text field, text input, or text area.

Solution

Use the instance's text property.

Discussion

Whether you are using a text field, text input, or text area, you can retrieve the value in the same way. Each of these text form controls has a text property that returns the current text value. For example, the following retrieves the text value from a text input with an instance name of ctiUsername and then saves it to a variable named sUsername:

 var sUsername:String = ctiUsername.text; 

Keep in mind that you'll most often want to retrieve the value from a text form control only after the user has clicked on a submit button. Therefore the ActionScript code should be placed within a click( ) method on a listener object or within a button's onRelease( ) event handler method. The following example uses a listener object registered with a button instance named cbtSubmit. When the user clicks on the button, the value that the user has entered into the ctiUsername text input gets displayed in the Output panel while you are testing the movie:

 var oListener:Object = new Object(); oListener.click = function(oEvent:Object):Void {   trace(ctiUsername.text); }; cbtSubmit.addEventListener("click", oListener); 




Flash 8 Cookbook
Flash 8 Cookbook (Cookbooks (OReilly))
ISBN: 0596102402
EAN: 2147483647
Year: 2007
Pages: 336
Authors: Joey Lott

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net