Using Components > Creating forms using components > Storing form data

 

Storing form data

An essential part of all forms is storing and updating the data entered by the user. The form data needs to be current and available to all pages of the form at all times, which means that the ActionScript for initializing the form and storing the data must precede all form pages in the Timeline.

In the FormExample.fla file, all of the code is defined in an Actions layer in frame 1 of the Timeline.

The Timeline showing the layer structure of the form
 

The following code initializes the form, creates the object defining the properties to store the data and set the initial values for each form element, and creates arrays to populate the list and combo boxes used in the form:

function initData()
{
// this function is called in frame 1 of the Frame Actions layer
// the following code ensures the form is only initialized once

	if ( inited )
	return;
	inited = true;

// create an object with properties to store the data and set the initial
// values or each UI element

	loginData = new Object();
	loginData.nameField ="";
	loginData.gender = "Female";
	loginData.cityIndex = 1;
	loginData.junkMail = true;
	loginData.interestIndex = undefined;
// define the arrays to populate the list and combo boxes in the form

cityTable = new Array("Berkeley", "San Francisco", "San Jose", "Oakland", 
"El Cerrito", "Walnut Creek");
interestTable = new Array("Golf", "Ski", "Flash Programming", "Hiking");

}

The initData function is called from frame 1 in a Frame Actions layer using the following code:

initData();

Once you have initialized your form and established a means for storing the data entered by the user, you use the data to navigate and display the form pages.