Previous Page
Next Page

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

Recipe 14.4. Preselecting Date Control Values

Problem

You want a Flash form date control to initialize with a particular value selected.

Solution

Assign a Date object to the component instance's selectedDate property.

Discussion

The selectedDate property of a date field or date chooser component instance is a read/write property. That means that you can use it not only for retrieving a user-selected value, but also to programmatically assign a value. The selectedDate property must be in the format of an ActionScript Date object. Though you can create a Date object in a variety of ways, the simplest here is to use the Date constructor in a new statement, passing the constructor three parameters: the year, month, and date. The following example creates a new Date object that represents December 01, 2010, and assigns it to a variable named dSomeDay:

	var dSomeDay:Date = new Date(2010, 11, 1);

You may notice that the month value for December is 11, and not 12. This is because the month indices for the Date class start with 0 instead of 1. Therefore, January is 0, February is 1, March is 2, and so on.

After you've created the date, you can assign it to the date chooser or date field's selectedDate property. The following example assigns the value from dSomeDay to the selectedDate property of a date field named cdfAppointment:

	cdfAppointment.selectedDate = dSomeDay;

Of course, you could skip the intermediate step of assigning the date to a variable first and simply create the date while assigning it to the selectedDate property, as in the following statement:

	cdfAppointment.selectedDate = new Date(2010, 11, 1); 

When you assign a date to the selectedDate property of a date chooser, the calendar will display the month for that selected date and highlight the selected date. When you assign a date to the selectedDate property of a date field, the value is displayed in the text field. If the user clicks on the button to pick another date, the calendar will display the month for the selected date with the selected date highlighted.

See Also

Recipe 13.9, Recipe 13.16

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