Showing paste #t6aiq by pushminakazi@apache.org: (Show raw paste)

<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:mx="library://ns.apache.org/royale/mx" xmlns:fx="http://ns.adobe.com/mxml/2009"  paddingBottom="2" paddingLeft="2" paddingRight="2" paddingTop="2" horizontalGap="0" verticalAlign="middle">
	
	<fx:Metadata>
		COMPILE::SWF
			{
				[Event(name="change", type="flash.events.Event")]
			}
		COMPILE::JS
			{
				[Event(name="change", type="org.apache.royale.events.Event")]
			}
	</fx:Metadata>
	
	<fx:Script>
		<![CDATA[
			import mx.controls.Alert;
			import org.apache.royale.events.Event;
			
			[Bindable] private var _selectedDate:Date = new Date();
			[Bindable] private var _text:String = "";
			[Bindable] [Inspectable(defaultValue='5', category="Other", enumeration="1,5,10,15,30")] 
			public var minuteIncrement:int = 5;
			
			public function get text():String{
				this.validateNow();
				return this._text;
			}
			[Bindable]
			public function set text(aTime:String):void{
				var hour:String = "0";
				var min:String = "0";
				var sec:String = "0";
				var lsAMPM:String = "AM";
				
				var liPos1:int = aTime.indexOf(":");
				if(liPos1>0)
				{
					hour = aTime.substring(0,liPos1);
					hours.value = isNaN( Number(hour)) ?0: Number(hour);
					aTime = aTime.substring(liPos1+1);
					liPos1 = aTime.indexOf(":");
					if(liPos1>0)
					{
						min = aTime.substring(0,liPos1);
						minutes.value = isNaN( Number(min)) ?0: Number(min);
						aTime = aTime.substring(liPos1+1);
						liPos1 = aTime.indexOf(" ");
						if(liPos1>0)
						{
							sec = aTime.substring(0,liPos1);
							seconds.value = isNaN( Number(sec)) ?0: Number(sec);
							aTime = aTime.substring(liPos1+1);
							liPos1 = aTime.indexOf(" ");
							if(liPos1>0)
							{
								lsAMPM = aTime.substring(0,liPos1);
							}
							else
							{
								lsAMPM =aTime;
							}
						}
					}
				}
				if (lsAMPM == "PM")
					ampm.selectedValue = 2;
				else
					ampm.selectedValue = 1;
				this.validateNow();
			}
			
			public function get selectedDate():Date
			{
				this.validateNow();
				return this._selectedDate;
			}
			
			[Bindable]
			public function set selectedDate(value:Date):void
			{
				
				this._selectedDate = value
				//this.date.selectedDate = this._selectedDate
				if(value.getHours() >= 12)
				{
					this.ampm.selectedValue = 2;
				}
				else
				{
					this.ampm.selectedValue = 1;
				}
				
				if(value.getHours() < 13 )
					this.hours.value = value.getHours()
				else
					this.hours.value = value.getHours() - 12
				
				if(value.getHours() == 0)
					this.hours.value = 12;
				
				this.minutes.value = value.getMinutes()
				this.validateNow();
				
			}
			
			override public function validateProperties():void
			{
				super.validateProperties();
				
			}
			
			public function handleChange():void
			{
				var strAMPM:String = "";
				var militaryHours:int = hours.value;
				if(ampm.selectedValue == 2 && hours.value != 12)
					militaryHours = hours.value+12; 
				else if(ampm.selectedValue == 1 && hours.value == 12)
					militaryHours = 0;
				
				if(ampm.selectedValue == 2 )
					strAMPM = "PM";
				else 
					strAMPM = "AM";
				
				var selDate:Date = new Date();//this.date.selectedDate;
				var date:Date = new Date(
					selDate.getFullYear(),
					selDate.getMonth(),
					selDate.getDate(),
					militaryHours,
					minutes.value,
					seconds.value)
				
				this.selectedDate = date;
				_text = hours.value+":"+minutes.value+":"+seconds.value+" "+strAMPM;
				this.invalidateProperties();
				this.validateNow();
				this.dispatchEvent(new org.apache.royale.events.Event("change"));
				
			}
		]]>
	</fx:Script>
	<mx:NumericStepper id="hours" minimum="1" maximum="12" stepSize="1" change="handleChange()" valueCommit="handleChange()" textAlign="center" width="44"/>
	<mx:Label text=":" textAlign="center" width="8"/>
	<mx:NumericStepper id="minutes" minimum="0"  maximum="59" stepSize="{minuteIncrement}" change="handleChange()" valueCommit="handleChange()" textAlign="center" width="44"/>
	<mx:Label text=":" textAlign="center" width="8"/>
	<mx:NumericStepper id="seconds" minimum="0"  maximum="59" stepSize="{minuteIncrement}" change="handleChange()" valueCommit="handleChange()" textAlign="center" width="44"/>
	<mx:Spacer width="5"/>
	<mx:RadioButtonGroup id="ampm" selectedValue="1" change="this.handleChange()"/>
	<mx:RadioButton id="am" value="1" label="AM" group="{ampm}" selected="true"/>
	<mx:RadioButton id="pm" value="2" label="PM" group="{ampm}"/>
</mx:HBox>
Make a new paste