2 May 2011
Beginning
In this exercise you will use inline ActionScript to display the date selected from a DateChooser control. You will then use a function to achieve the same result as the inline ActionScript (see Figure 1).
In this exercise you will learn how to:
In this section you will use inline ActionScript to handle a change in the application.
id property a value of pickupDate (see Figure 2).
Script block.Script block, import the Alert class:import mx.controls.Alert;
pickupDate DateChooser control.change property assigned to run the show() method of the Alert package:<mx:DateChooser id="pickupDate"
change="Alert.show()"
... />
Alert.show() function to display the text You have selected, followed by the date selected from the pickupDate DateChooser control, using the toDateString() function; this displays the date as a string.Note: Use single quotes inside of the Alert.show() method, because the change event already uses double quotes.
<mx:DateChooser id="pickupDate"
change="Alert.show('You have selected ' +
pickupDate.selectedDate.toDateString())"
.../>
pickupDate DateChooser control, click a date. You should see the Alert window with the date you selected (see Figure 3).
id property with a value of returnDate:<mx:DateChooser id="returnDate"
... />
change property and its value from the pickupDate DateChooser control and paste it within the opening tags for the returnDate DateChooser control.<mx:DateChooser id="returnDate"
change="Alert.show('You have selected ' +
pickupDate.selectedDate.toDateString())"
... />
Alert.show() method to returnDate.<mx:DateChooser id="returnDate"
change="Alert.show('You have selected ' + returnDate.selectedDate.toDateString())"
... />
You should see that the date selected is displayed using the Alert window for both DateChooser controls.
In this section, you will create a function to handle the change event for a DateChooser control.
Script block.import statement, create a private function named dateChangeHandler() that takes no parameters and returns a void data type.private function dateChangeHandler():void
{
}
pickupDate DateChooser control and cut the Alert.show() method from the change event.dateChangeHandler() function:<mx:DateChooser id="pickupDate"
change="dateChangeHandler()"
... />
dateChangeHandler() function, paste the Alert.show() method that you cut from the change event. Remember to append a semicolon.private function
dateChangeHandler():void
{
Alert.show('You have selected ' + pickupDate.selectedDate.toDateString());
}
pickupDate DateChooser control. The Alert message displays the date you selected (see Figure 4).
returnDate DateChooser control.change property, replace the value with a call to the dateChangeHandler() function:<mx:DateChooser id="returnDate"
change="dateChangeHandler()" />
You should see the error display shown in Figure 5.
You will fix this error in the next exercise.
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.