Select Date and Time with DateTime selector component for Flex

Tagged:  

Because there is nothing like that supplied with Flex 3, I decided to make my own little component.

Feel free to use i:

Component source code:

<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()">
<mx:Script>
    <![CDATA[
        import mx.events.FlexEvent;
       
        /**
         * AM/PM format and 24Hrs format. Not yet implemented :)
         * */
        public var format:int;
       
        private function init():void {
            date.selectedDate = new Date();
        }
       
        [Bindable]
        public function get selectedDate():Date {
            if(date.selectedDate) {
                var result:Date = date.selectedDate;
                result.setHours(hours.value,minutes.value,seconds.value);
                return result
            } else {
                return null;
            }
        }
       
        public function set selectedDate(value:Date):void {
            hours.value = value.getHours();
            minutes.value = value.getMinutes();
            seconds.value = value.getSeconds();
            date.selectedDate = value;
        }
       
        private function onAnyChange(event:Event):void {
            var new_event:Event = new Event(Event.CHANGE);
            this.dispatchEvent(new_event);
        }
    ]]>
</mx:Script>
    <mx:NumericStepper minimum="0" maximum="24" stepSize="1" width="40" id="hours" change="onAnyChange(event)"/>
    <mx:NumericStepper minimum="0" maximum="59" stepSize="1" width="40" id="minutes" change="onAnyChange(event)"/>
    <mx:NumericStepper minimum="0" maximum="59" stepSize="1" width="40" id="seconds" change="onAnyChange(event)"/>
    <mx:DateField width="90" id="date" change="onAnyChange(event)" showToday="true"/>
</mx:HBox>

And test application:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:components="org.ectar.components.*" creationComplete="init()">
    <mx:Script>
        <![CDATA[
       
            private function init():void {
                dateTime.addEventListener(Event.CHANGE,onDateChange);
            }
           
            private function onDateChange(event:Event):void {
                var target:DateTimeSelector = event.target as DateTimeSelector;
                dateTimeLabel.text = target.selectedDate.toString();
            }
        ]]>
    </mx:Script>
    <components:DateTimeSelector id="dateTime" horizontalCenter="0" verticalCenter="0"/>
    <mx:Label width="224" id="dateTimeLabel" textAlign="center" horizontalCenter="0" verticalCenter="28"/>
</mx:Application>

 

 

Comments

Seems nice, but I can select hour 24, minutes 59 jeje
Thanks, I've learned from this.

It's simple and it works great.
Thank you.

Thank you :)

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.
all information is copyright of riahut.com