Ultrashock Tutorials > Flash MX 2004 > Flash MX 2004 UI Components  
 
by Aral Balkan,  BitsAndPixels.co.uk 
Download Source Files (5MB!)  
 
Flash MX 2004 UI Components
 

 01. v1 Components, We Hardly Knew Ye 
 02. Button Component 
 03. Alert Component 
 04. Checkbox Component 
 05. Radio Buttons 
 06. The List Box family of Components 
 07. Date Chooser Component 
 08. Date Field Component 
 09. Label Component 

 10. Loader / Progress Bar Components 
 11. Numeric Stepper Component 
 12. Text Area/Input Components 
 13. Menu / Menu Bar Components 
 14. Scroll Pane Component 
 15. Window Component 
 16. Tree Component 
 17. Accordion Component 
 18. Conclusion 

Aral Balkan is co-author of
Flash MX Components Most Wanted.
Click to check it out at Amazon.com!
- discuss this tutorial -

07. Date Chooser Component

The Date Chooser is the new name for the Calendar component that was introduced in Flash MX. Using it is very simple, as the following example will show.

  1. Start a new FLA. Use the screenshot below as a guide when laying out your Flash application in the following steps.



  2. Create a new layer. Label the topmost layer Actions and the one under it, Components.

  3. Drag a TextArea component and place it at the top of the Stage. You will use this to display the selected date in the Date Chooser. Give the TextArea component the instance name statusMessage. In its text property, type in the default text to display when the application first runs. In this case, this is: "Select dates on the DateChooser component, below."



  4. Drag a DateChooser component on Stage and place it underneith the TextArea component. Give it the instance name myDateChooser and take a look at the various parameters you have available for this component. Using the dispabledDays parameter, you can set dates that appear as disabled (which the user cannot select), you can also specify the first day of the week (defaults to 0, which is Sunday) and specify the names of the Months (in our own language, for example). If showToday is set to true (default), the current date will appear highlighted in the component.



  5. In Frame 1 of the Actions Layer, enter the following code:
    myDateListener = new Object();
    
    myDateListener.change = function(eventObj)
    {
        var eventSource = eventObj.target;
               
        var theSelectedDate = eventSource.selectedDate; 
        // compose the message
        var msg = "You selected " + theSelectedDate;
               
        // display the message 
        statusMessage.text = msg;
    }
               
    myDateChooser.addEventListener("change", myDateListener);
  6. Test the movie and click around on the calendar control to see the status message change. You can interact with the final application below.


If you have been reading this tutorial from the beginning, you will no doubt have noticed some striking similarities in the way you use the various components. Just like the List Box, Combo Box and Grid components, the DateChooser component broadcasts a change event. You can look at the selectedDate property in the target of the event object that gets passed to the change event handler to learn the date that the user selected (this is a regular date object.) You may be balking the complexity of the dates that get displayed in the TextArea component. It's easy to make them fit for human consumption by formatting them. To do this:

  1. Replace the script in Frame 1 of the Actions layer with the following one:
    myDateListener = new Object();
               
    myDateListener.change = function(eventObj)
    {
        var eventSource = eventObj.target;
               
        var theSelectedDate = eventSource.selectedDate; 
        
    // format the date var theDate = theSelectedDate.getDate(); var theMonth = theSelectedDate.getMonth() + 1; var theYear = theSelectedDate.getFullYear(); var formattedDate = theDate + "/" + theMonth + "/"+ theYear; // compose the message msg = "You selected " + formattedDate; // display the message statusMessage.text = msg; } myDateChooser.addEventListener ("change", myDateListener);
  2. Test the movie, click on some dates and note the formatted output in the Text Area component. You can interact with the version below to see this.

- discuss this tutorial -
 
©2003 Ultrashock.com - All rights reserved