14.2. Performing Actions When the User Makes a Date Selection

Problem

You want Flash to perform some actions when the user chooses a value from a date chooser or a date field.

Solution

Define a listener object with a change() method.

Discussion

Both the date chooser and date field dispatch a change event when the user selects a date value. Thus you can use a listener object to detect the change event and perform some actions when that occurs. For example, if you are using a date chooser to allow the user to select a date for which he or she wants to see a schedule, you may want the event to cause Flash to display some corresponding schedule information in a text area.

In the following code, a listener object is defined and registered such that when the user makes a selection from a date chooser named cdcSchedule, the selected date is displayed in the Output panel:

	var oListener:Object = new Object();
	oListener.change = function(oEvent:Object):Void {
	  trace(oEvent.target.selectedDate);
	};
	cdcSchedule.addEventListener("change", oListener);

For more details on using a listener object as well as the parameter passed to the listener object’s method, see Recipe 13.10.

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.