13.16. Retrieving Date Values

Problem

You want to retrieve a date from a date form control.

Solution

If you are using a date chooser or date field, use the instance’s selectedDate property. Otherwise, use the FormController component to handle your form processing.

Discussion

The date chooser and date field components both have a selectedDate property that returns the date that the user has selected. The value that the property returns in either case is in the format of an ActionScript Date object. In most cases, you will want to retrieve the selected date only after users have indicated that they want to process the form data. Typically, that is done by clicking a submit button. The following code shows an example in which the selected date from a date chooser named cdcCalendar is retrieved and displayed when the user clicks a button:

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

If you are not using a date field or a date chooser, but rather a text input or input text field, you can simply retrieve the information the user has input via the text property as discussed in Recipe 13.11. However, as was mentioned in Recipe 13.9, verifying that the information represents a valid date requires some advanced ActionScript code. Therefore, unless you are very familiar with ActionScript, you will likely find it much simpler to use a FormController component to manage your ...

Get Flash 8 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.