Recipe 13.9. Adding a Form Control for Collecting Date InformationProblemYou want to add a form control that allows the user to input a date (year, month, and day). SolutionUse a DateField or DateChooser component (available only in Flash Professional). Alternatively, use a form control for allowing the user to input text and restrict the allowable characters. DiscussionFlash Professional includes many components that are not part of the standard version, among which are the DateField and DateChooser components. These two components provide you with a convenient way of prompting a user to input a date value. A date chooser displays a calendar (one month at a time) from which the user can select a date. A date field is a slight variation on the date chooser. In fact, you'll notice that the date field actually includes a nested date chooser. However, a date field doesn't require you to display the calendar at all times. Instead, the nested date chooser is hidden except when the user is actively selecting a date. Otherwise, all that the user sees is a field (similar to a text input) with a small button to the right from which the user can open and close the nested date chooser. The date field is often more appropriate when space is a consideration. You can create a date field or a date chooser by dragging an instance from the Component Inspector panel onto the stage and giving it an instance name (exp 3pod.com) via the Property inspector. Both component types have the same set of parameters that you can configure. The default parameter settings are likely suitable for most situations. However, you can adjust the following settings if appropriate:
If you do not have Flash Professional, you can still prompt the user for a date value. However, the standard version does not provide any components specifically for that purpose. Instead, you can use a text input of an input text field. Because you'll be prompting the user for a date value in a specific format, you may want to restrict the allowable characters using the restrict parameter or the restrict property (see Recipe 13.6 for more details). For example, if you want the user to input the date value in the format of YYYY/MM/DD, set the restrict parameter of a text input to 0123456789/ so as to allow all numbers and the forward slash but no other characters. When you use a date field or a date chooser component, Flash automatically collects the data in the ActionScript Date format. That helps to eliminate a lot of potential error. When you use a text input or an input text field, Flash collects the information as regular text. Although restricting the allowable characters is helpful, it does not force the user to input a valid date. In order to confirm that the user has input a valid date value, you will need to use ActionScript that is rather advanced and beyond the scope of this book. If you are using the FormController component that is discussed in Recipe 13.17 you can use its built-in validation to verify the data. See AlsoRecipe 13.6 and Recipe 13.17 |
Tripod >> 3pod Tips & Learning and manuals for educations