Previous Page
Next Page

Tripod >> 3pod Tips & Learning and manuals for educations

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 (exp 3pod.com) 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);

Tripod >> 3pod Botom Tips & Learning and manuals for educations

Previous Page
Next Page

 

bluedot bluedots greydots pinkdots

Tripod >> 3pod Tips & Learning and manuals for educations